<?php
/**
 * Created by <xinxin.deng>.
 * Author: xinxin.deng
 * Date: 2018/11/7 16:09
 */

set_time_limit(0);
include_once dirname(dirname(dirname(dirname(dirname(__FILE__)))))."/common.php";
\ns_core\m_load::load("ns_model.message.message_explain");
\ns_core\m_load::load("ns_core.m_pinyin");
\ns_core\m_load::load("ns_core.m_config");
\ns_core\m_load::load_old("nn_logic/log_model/nn_log.class.php");
\ns_core\m_load::load_old("nn_logic/video/vod_index.class.php");
\ns_core\m_load::load_old("nn_logic/video/vod_media.class.php");
\ns_core\m_load::load_old("nn_logic/cp/cp.class.php");
\ns_core\m_load::load_np("np_http_curl.class.php");
class message extends \ns_model\message\message_explain
{
    private $arr_picture = null;

    private $arr_map = null;

    //一级分类,影片种类
    private $category_map = array (
        '0' => '电影',  //电影
        '1' => '电视剧',  //电视剧
        '2' => '娱乐,综艺',  //综艺
        '3' => '动画',  //动漫
        '4' => '音乐',  //音乐
        '5' => '纪实,纪录片',  //
        '6' => '法治,科教',  //教育
        '7' => '体育',  //体育
        '8' => '生活',  //生活
        '9' => '经济',  //财经
        '10' => '特别节目',//微电影
        '11' => '品牌专区',//品牌专区
        '12' => '广告',  //广告
        '13' => '新闻', //新闻
        '14' => '公开课',
        '15' => '外语及其他语言',
        '16' => '青少年',
        '17' => '播客',
        '18' => '游戏',
    );

    private $msg_id = '';
    private $source_id = '';
    private $arr_cp_config = array();

    private $arr_epg_file_set = array();//EPGFileSet
    private $arr_epg_file = array();//EPGFile

    //上游通过soap推送的数据
    public $csp_data = null;
    //上游发送的message_id
    public $str_message_id = null;
    /**
     * 片源清晰度映射数组
     * @var array
     */
    private $arr_file_definition_map = array(
        '0' => 'std',
        '1' => 'hd'
    );
    /**
     * 导演、演员等字段值的分隔符，黑龙江需要支持使用“、”分隔
     * @var array
     */
    public $arr_symbols = array (
        ",",
        " ",
        "/",
        "\\",
        "，",
        " ",
        "、"
    );


    public function init()
    {

    }
    public function explain($message)
    {
        \ns_core\m_load::load_np("np_xml2array.class.php");
        $this->msg_id = $message['nns_message_id'];
        $this->source_id = $message['nns_cp_id'];
        $this->arr_cp_config = \m_config::_get_cp_info($message['nns_cp_id']);
        $content = $this->get_message_content($message);
        if($content['ret'] !=0 || strlen($content['data_info']) <1)
        {
            $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败，消息ID[{$message['nns_message_id']}]" . $content['reason']);
            return $content;
        }
        $str_content = m_config::trim_xml_header($content['data_info']);
        if(!m_config::is_xml($str_content))
        {
            $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}]xml内容非xml结构");
            return \m_config::return_data(NS_CDS_FAIL,"消息ID[{$message['nns_message_id']}]xml内容非xml结构");
        }
        //解析下载的XML
        $dom = new DOMDocument('1.0', 'utf-8');
        $dom->loadXML($str_content);
        $xml = $dom->saveXML();
        $xml_arr = np_xml2array::getArrayData($xml);
        if ($xml_arr["ret"] == 0)
        {
            $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],解析得到的媒资元数据错误");
            return \m_config::return_data(1, "解析得到的媒资元数据错误");
        }
        if($message['nns_cp_id'] == 'sobey')
        {
            $arr_data = $this->parse_xml($message,$xml_arr);
        }
        else
        {
            $Objects = null;
            foreach ($xml_arr['data']['children'] as $v)
            {
                if (empty($Objects) && $v['name'] == 'Objects')
                {
                    $Objects = $v['children'];
                }
                else if (empty($this->arr_map) && $v['name'] == 'Mappings')
                {
                    $this->arr_map = $v['children'];
                }
            }
            //Series数据数组
            $arr_series = array ();
            //Program数据数组
            $arr_program = array ();
            //Movie数据数组
            $arr_movie = array ();
            //打点信息数据数组
            $arr_seekpoint = array ();
            //演员明星数据数组
            $arr_actor = array();
            //Channel
            $arr_channel = array ();                //直播频道
            //直播源
            $arr_physical_channel = array ();       //直播源
            //直播节目单
            $arr_schedule_record = array ();        //直播节目单
            if (!empty($Objects) && is_array($Objects))
            {
                foreach ($Objects as $obj)
                {
                    if ($obj['attributes']['ElementType'] == 'Series')
                    {
                        $arr_series[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'Program')
                    {
                        $arr_program[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'Movie')
                    {
                        $arr_movie[]=$this->make_key_value_arr($obj);
                    }
                    //直播频道
                    else if ($obj['attributes']['ElementType'] == 'Channel')
                    {
                        $arr_channel[]=$this->make_key_value_arr($obj);
                    }
                    //直播片源
                    else if ($obj['attributes']['ElementType'] == 'PhysicalChannel')
                    {
                        $arr_physical_channel[]=$this->make_key_value_arr($obj);
                    }
                    //节目单
                    else if ($obj['attributes']['ElementType'] == 'ScheduleRecord')
                    {
                        $arr_schedule_record[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'Picture')
                    {
                        $this->arr_picture[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'SeekPoint')
                    {
                        $arr_seekpoint[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'Cast')
                    {
                        $arr_actor[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'EPGFileSet')
                    {
                        $this->arr_epg_file_set[]=$this->make_key_value_arr($obj);
                    }
                    else if ($obj['attributes']['ElementType'] == 'EPGFile')
                    {
                        $this->arr_epg_file[]=$this->make_key_value_arr($obj);
                    }
                }
            }
        }
        //主媒资操作   主媒资增删改走以前老逻辑，基本没什么变化
        if (!empty($arr_series))
        {
            foreach ($arr_series as $val_series)
            {
                //主媒资删除
                if (strtoupper($val_series['Action']) == 'DELETE')
                {
                    $del_series = array(
                        'base_info'=>array(
                            'nns_asset_import_id'=>$val_series['ContentID'],
                            'nns_import_source'=>isset($val_series['nns_import_source']) ? $val_series['nns_import_source'] : evn::get("project"),
                            'nns_cp_id'=>$message['nns_cp_id'],
                        ),
                    );
                    $result = $this->vod_action('delete', $del_series);
                }
                else
                {
                    //默认一级分类为电影
                    $view_type = 0;
                    if ($message['nns_cp_id'] == 'JSCN')
                    {
                        $val_series['key_val_list']['CategoryName'] = (isset($val_series['key_val_list']['PgmCategory']) && strlen($val_series['key_val_list']['PgmCategory']) >0) ? $val_series['key_val_list']['PgmCategory'] : '电影';
                    }

                    $asset_category = $val_series['key_val_list']['Type'] ? $val_series['key_val_list']['Type'] : '电影';
                    if(isset($val_series['key_val_list']['ViewType']) && strlen($val_series['key_val_list']['ViewType']) >0)
                    {
                        $view_type = $val_series['key_val_list']['ViewType'];
                    }
                    else
                    {
                        foreach ($this->category_map as $index => $v)
                        {
                            $v = explode(',', $v);
                            if(!is_array($v) || empty($v))
                            {
                                continue;
                            }
                            foreach ($v as $_v)
                            {
                                if (stripos($asset_category, $_v) !== false)
                                {
                                    $view_type = $index;
                                    break 2;
                                }
                            }
                        }
                    }
                    //$asset_category = (isset($val_series['key_val_list']['CategoryName']) && strlen($val_series['key_val_list']['CategoryName']) >0) ? $val_series['key_val_list']['CategoryName'] : '电影';
                    $do_category = array(
                        'base_info'=>array(
                            'nns_name'=>$asset_category,   //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_import_category_id'=>'', //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_cp_id'=>$message['nns_cp_id'],
                            'nns_import_parent_category_id'=>'',
                            'nns_video_type'=>'0',  //媒资类型  0 点播 | 1 直播
                        ),
                    );
                    $result = $this->category_action('add', $do_category);
                    if($result['ret'] !=0)
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $result['reason']);
                        return $result;
                    }
                    if(!isset($result['data_info']['base_info']['nns_id']) || strlen($result['data_info']['base_info']['nns_id']) <1)
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $result['reason']);
                        return m_config::return_data(1,'创建栏目失败');
                    }
                    $nns_category_id = $result['data_info']['base_info']['nns_id'];
                    foreach ($this->category_map as $index => $v)
                    {
                        if (stripos($v, $asset_category) !== false)
                        {
                            $view_type = $index;
                            break;
                        }
                    }
                    if($view_type == 0 && isset($val_series['key_val_list']['VolumnCount']) && $val_series['key_val_list']['VolumnCount'] >1)
                    {
                        $view_type = 1;
                    }
                    #TODO
                    $arr_img = $this->handle_picture_v3($val_series['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_series['key_val_list'] = array_merge($val_series['key_val_list'], $arr_img);
                    }
                    $pinyin = m_pinyin::get_pinyin_letter($val_series['key_val_list']['Name']);
                    $add_series = array(
                        'base_info' => array(
                            'nns_name' => isset($val_series['key_val_list']['Name']) ? $val_series['key_val_list']['Name'] : '',
                            'nns_view_type' => $view_type,
                            'nns_org_type' => '0',
                            'nns_tag' => '26,',
                            'nns_director' => isset($val_series['key_val_list']['WriterDisplay']) ? $val_series['key_val_list']['WriterDisplay'] : '',
                            'nns_actor' => isset($val_series['key_val_list']['ActorDisplay']) ? $val_series['key_val_list']['ActorDisplay'] : '',
                            'nns_show_time' => (isset($val_series['key_val_list']['ReleaseYear']) && strlen($val_series['key_val_list']['ReleaseYear']) > 0) ? date("Y", strtotime($val_series['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_view_len' => isset($val_series['key_val_list']['Duration']) ? $val_series['key_val_list']['Duration'] : 0,
                            'nns_all_index' => isset($val_series['key_val_list']['VolumnCount']) ? $val_series['key_val_list']['VolumnCount'] : 1,
                            'nns_new_index' => isset($val_series['key_val_list']['NewCount']) ? $val_series['key_val_list']['NewCount'] : 0,
                            'nns_area' => isset($val_series['key_val_list']['OriginalCountry']) ? $val_series['key_val_list']['OriginalCountry'] : '',
                            'nns_image0' => isset($val_series['key_val_list']['bigpic']) ? $val_series['key_val_list']['bigpic'] : '',
                            'nns_image1' => isset($val_series['key_val_list']['middlepic']) ? $val_series['key_val_list']['middlepic'] : '',
                            'nns_image2' => isset($val_series['key_val_list']['smallpic']) ? $val_series['key_val_list']['smallpic'] : '',
                            'nns_image3' => '',
                            'nns_image4' => '',
                            'nns_image5' => '',
                            'nns_summary' => isset($val_series['key_val_list']['Description']) ? $val_series['key_val_list']['Description'] : '',
                            'nns_remark' => isset($val_series['key_val_list']['Kind']) ? $val_series['key_val_list']['Kind'] : '',
                            'nns_category_id' => $nns_category_id,
                            'nns_play_count' => '0',
                            'nns_score_total' => '0',
                            'nns_score_count' => '0',
                            'nns_point' => isset($val_series['key_val_list']['ViewPoint']) ? $val_series['key_val_list']['ViewPoint'] : '0',
                            'nns_copyright_date' => (isset($val_series['key_val_list']['ReleaseYear']) && strlen($val_series['key_val_list']['ReleaseYear']) > 0) ? date("Y", strtotime($val_series['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_asset_import_id' => $val_series['ContentID'],
                            'nns_pinyin' => (isset($val_series['key_val_list']['Spell']) && strlen($val_series['key_val_list']['Spell']) > 0) ? $val_series['key_val_list']['Spell'] : $pinyin,
                            'nns_pinyin_length' => (isset($val_series['key_val_list']['Spell']) && strlen($val_series['key_val_list']['Spell']) > 0) ? strlen($val_series['key_val_list']['Spell']) : strlen($pinyin),
                            'nns_alias_name' => isset($val_series['key_val_list']['AliasName']) ? $val_series['key_val_list']['AliasName'] : '',
                            'nns_eng_name' => isset($val_series['key_val_list']['EnglishName']) ? $val_series['key_val_list']['EnglishName'] : '',
                            'nns_language' => isset($val_series['key_val_list']['Language']) ? $val_series['key_val_list']['Language'] : '',
                            'nns_text_lang' => isset($val_series['key_val_list']['Language']) ? $val_series['key_val_list']['Language'] : '',
                            'nns_producer' => isset($val_series['key_val_list']['ContentProvider']) ? $val_series['key_val_list']['ContentProvider'] : '',
                            'nns_screenwriter' => isset($val_series['key_val_list']['WriterDisplay']) ? $val_series['key_val_list']['WriterDisplay'] : '',
                            'nns_play_role' => '',
                            'nns_copyright_range' => isset($val_series['key_val_list']['ContentProvider']) ? $val_series['key_val_list']['ContentProvider'] : '',
                            'nns_vod_part' => '',
                            'nns_keyword' => isset($val_series['key_val_list']['Keywords']) ? $val_series['key_val_list']['Keywords'] : '',
                            'nns_import_source' => isset($val_series['nns_import_source']) ? $val_series['nns_import_source'] : evn::get("project"),
                            'nns_kind' => isset($val_series['key_val_list']['Kind']) ? $val_series['key_val_list']['Kind'] : '',
                            'nns_copyright' => isset($val_series['key_val_list']['ContentProvider']) ? $val_series['key_val_list']['ContentProvider'] : '',
                            'nns_clarity' => '',
                            'nns_image_v' => isset($val_series['key_val_list']['verticality_img']) ? $val_series['key_val_list']['verticality_img'] : '',
                            'nns_image_s' => isset($val_series['key_val_list']['square_img']) ? $val_series['key_val_list']['square_img'] : '',
                            'nns_image_h' => isset($val_series['key_val_list']['horizontal_img']) ? $val_series['key_val_list']['horizontal_img'] : '',
                            'nns_cp_id' => $message['nns_cp_id'],
                            'nns_conf_info' => '',
                            'nns_ext_url' => '',
                        ), //基本信息（存储于nns_vod表中）
                        'ex_info' => array(
                            'svc_item_id' => '',
                            'month_clicks' => '',
                            'week_clicks' => '',
                            'base_id' => '',
                            'asset_path' => '',
                            'ex_tag' => '',
                            'full_spell' => '',
                            'awards' => '',
                            'year' => '',
                            'play_time' => '',
                            'channel' => '',
                            'first_spell' => '',
                        ), //扩展信息（存储于nns_vod_ex表中）
                    );
                    //字段待修改4-14
                    $result = $this->vod_action('add', $add_series);
                }

                if ($result['ret'] != 0)
                {
                    $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $result['reason']);
                    return $result;
                }
            }
        }
        //分集操作   分集删除走以前的老逻辑，分集注册  则组装分集和片源的信息到redis，分集更新则查询redis关联数据
        if (!empty($arr_program))
        {
            foreach ($arr_program as $val_program)
            {
                //分集删除
                if (strtoupper($val_program['Action']) == 'DELETE')
                {
                    $del_program = array(
                        'base_info' => array(
                            'nns_import_id' => $val_program['ContentID'],
                            'nns_import_source' => isset($val_program['nns_import_source']) ? $val_program['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $re = $this->index_action('delete', $del_program);
                    if ($re['ret'] != 0)
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $re['reason']);
                        $re['ret'] = 1;
                        return $re;
                    }
                } else
                {
                    if ($message['nns_cp_id'] == 'JSCN' && $val_program['key_val_list']['SeriesFlag'] == 0)
                    {
                        $p_series[0] = $val_program['ContentID'];
                    }
                    else
                    {
                        $arr_p_series = $this->get_map_info_v2('Program', $this->arr_map, $val_program['ContentID']);
                        $p_series = array_keys($arr_p_series);
                        //分集不存在集数字段
                        if (!isset($val_program['key_val_list']['Sequence']) || !strlen($val_program['key_val_list']['Sequence']) > 0)
                        {
                            $val_program['key_val_list']['Sequence'] = isset($arr_p_series[$p_series[0]]['key_val_list']['Sequence']) ? $arr_p_series[$p_series[0]]['key_val_list']['Sequence'] : 0;
                        }
                        if (substr($message['nns_cp_id'], 0, 5) == 'fuse_')
                        {
                            $val_program['key_val_list']['Sequence']++;
                        }
                    }
                    $res = nl_asset_incidence_relation::query_asset_relation(m_config::get_dc(), 'video', $p_series[0], $message['nns_cp_id'], 0);
                    if (!is_array($res['data_info']))
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $res['reason']);
                        $res['ret'] = 6;
                        $res['reason'] = "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $res['reason'];
                        return $res;
                    }
                    $arr_img = $this->handle_picture_v3($val_program['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_program['key_val_list'] = array_merge($val_program['key_val_list'], $arr_img);
                    }

                    $add_index = array(
                        'base_info' => array(
                            'nns_name' => isset($val_program['key_val_list']['Name']) ? $val_program['key_val_list']['Name'] : '',
                            'nns_index' => $val_program['key_val_list']['Sequence'],
                            'nns_time_len' => '',
                            'nns_summary' => isset($val_program['key_val_list']['Description']) ? $val_program['key_val_list']['Description'] : '',
                            'nns_image' => isset($val_program['key_val_list']['Picture']) ? $val_program['key_val_list']['Picture'] : '',
                            'nns_play_count' => 0,
                            'nns_score_total' => 0,
                            'nns_score_count' => 0,
                            'nns_video_import_id' => $res['data_info'][0]['nns_asset_import_id'],
                            'nns_import_id' => $val_program['ContentID'],
                            'nns_import_source' => isset($val_program['nns_import_source']) ? $val_program['nns_import_source'] : evn::get("project"),
                            'nns_director' => isset($val_program['key_val_list']['WriterDisplay']) ? $val_program['key_val_list']['WriterDisplay'] : '',
                            'nns_actor' => isset($val_program['key_val_list']['ActorDisplay']) ? $val_program['key_val_list']['ActorDisplay'] : '',
                            'nns_release_time' => (isset($val_program['key_val_list']['ReleaseYear']) && strlen($val_program['key_val_list']['ReleaseYear']) > 0) ? date("Y-m-d", strtotime($val_program['key_val_list']['ReleaseYear'])) : date("Y-m-d"),
                            'nns_update_time' => date("Y-m-d"),
                            'nns_watch_focus' => '',
                            'nns_cp_id' => $message['nns_cp_id'],
                            'nns_conf_info' => '',
                            'nns_ext_url' => '',
                        ),
                        'ex_info' => array(
                            'isintact' => '',
                            'subordinate_name' => '',
                            'initials' => '',
                            'publisher' => '',
                            'first_spell' => '',
                            'caption_language' => '',
                            'language' => isset($val_program['key_val_list']['Language']) ? $val_program['key_val_list']['Language'] : '',
                            'region' => '',
                            'adaptor' => '',
                            'sreach_key' => '',
                            'event_tag' => '',
                            'year' => '',
                            'sort_name' => '',
                        ),
                    );

                    //分集注入
                    $re = $this->index_action('add', $add_index);

                    if ($re['ret'] != 0)
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $re['reason']);
                        $re['ret'] = 1;
                        return $re;
                    }
                    else
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_SUCCE, "消息接收成功,等待注入,消息ID[{$message['nns_message_id']}]");
                    }
                }
            }
        }
        //片源操作
        if (!empty($arr_movie))
        {
            foreach ($arr_movie as $val_movie)
            {
                //片源删除
                if (strtoupper($val_movie['Action']) == 'DELETE')
                {

                    $del_movie = array(
                        'base_info' => array(
                            'nns_import_id' => $val_movie['ContentID'],
                            'nns_import_source' => isset($val_movie['nns_import_source']) ? $val_movie['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $re = $this->media_action('delete', $del_movie);
                    if ($re['ret'] != 0)
                    {
                        $re['ret'] = 1;
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $re['reason']);
                        return $re;
                    }
                } //片源修改
                else
                {
                    $arr_p_program = $this->get_map_info_v2('Movie', $this->arr_map, $val_movie['ContentID']);
                    $arr_p_program = array_keys($arr_p_program);
                    $index_info = nl_asset_incidence_relation::query_asset_relation(m_config::get_dc(), 'index', $arr_p_program[0], $message['nns_cp_id'], 1);

                    if (!is_array($index_info['data_info']))
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $re['reason']);
                        //返回分集未注入
                        $re['ret'] = 7;
                        $re['reason'] = "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $index_info['reason'];
                        return $re;
                    }

                    $index_import_id = $arr_p_program[0];
                    $vod_import_id = $index_info['data_info'][0]['nns_asset_import_id'];

                    //片源参数
                    $add_media = array(
                        'base_info' => array(
                            'nns_name' => isset($val_movie['key_val_list']['Name']) ? $val_movie['key_val_list']['Name'] : '',
                            'nns_type' => 1,
                            'nns_url' => isset($val_movie['key_val_list']['FileURL']) ? $val_movie['key_val_list']['FileURL'] : '',
                            'nns_tag' => '26,',
                            'nns_mode' => isset($val_movie['key_val_list']['MediaMode']) ? $val_movie['key_val_list']['MediaMode'] : '',
                            'nns_kbps' => isset($val_movie['key_val_list']['BitRateType']) ? $val_movie['key_val_list']['BitRateType'] : '',
                            'nns_content_id ' => $val_movie['ContentID'],
                            'nns_content_state' => 0,
                            'nns_filetype' => isset($val_movie['key_val_list']['FileType']) ? $val_movie['key_val_list']['FileType'] : 'ts',
                            'nns_play_count' => '0',
                            'nns_score_total' => '0',
                            'nns_score_count' => '0',
                            'nns_video_import_id' => $vod_import_id,
                            'nns_index_import_id' => $index_import_id,
                            'nns_import_id' => $val_movie['ContentID'],
                            'nns_import_source' => isset($val_movie['nns_import_source']) ? $val_movie['nns_import_source'] : evn::get("project"),
                            'nns_dimensions' => isset($val_movie['key_val_list']['Dimensions']) ? $val_movie['key_val_list']['Dimensions'] : '2D',
                            'nns_ext_url' => '',
                            'nns_file_size' => isset($val_movie['key_val_list']['FileSize']) ? $val_movie['key_val_list']['FileSize'] : 0,
                            'nns_file_time_len' => isset($val_movie['key_val_list']['TimeLen']) ? $val_movie['key_val_list']['TimeLen'] : 0,
                            'nns_file_frame_rate' => isset($val_movie['key_val_list']['FrameRate']) ? $val_movie['key_val_list']['FrameRate'] : 0,
                            'nns_file_resolution' => isset($val_movie['key_val_list']['Resolution']) ? $val_movie['key_val_list']['Resolution'] : 0,
                            'nns_cp_id' => $message['nns_cp_id'],
                            'nns_ext_info' => '',
                            'nns_drm_enabled' => isset($val_movie['key_val_list']['DrmEnabled']) ? $val_movie['key_val_list']['DrmEnabled'] : 0,
                            'nns_drm_encrypt_solution' => isset($val_movie['key_val_list']['DrmEncryptSolution']) ? $val_movie['key_val_list']['DrmEncryptSolution'] : '',
                            'nns_drm_ext_info' => '',
                            'nns_domain' => isset($val_movie['key_val_list']['Domain']) ? $val_movie['key_val_list']['Domain'] : 0,
                            'nns_media_type' => isset($val_movie['key_val_list']['VideoType']) ? $val_movie['key_val_list']['VideoType'] : 1,
                            'nns_original_live_id' => '',
                            'nns_start_time' => '',
                            'nns_media_service' => isset($val_movie['key_val_list']['ServiceType']) ? $val_movie['key_val_list']['ServiceType'] : 'HTTP',
                            'nns_conf_info' => '',
                            'nns_encode_flag' => isset($val_movie['key_val_list']['EncodeFlag']) ? $val_movie['key_val_list']['EncodeFlag'] : 0,
                            'nns_live_to_media' => isset($val_movie['key_val_list']['EncodeType']) ? $val_movie['key_val_list']['EncodeType'] : '',
                            'nns_media_service_type' => '',
                        ),
                        'ex_info' => array(
                            'file_hash' => '',
                            'file_width' => '',
                            'file_height' => '',
                            'file_scale' => '',
                            'file_coding' => '',
                        ),
                    );

                    $re = $this->media_action('add', $add_media);
                    if ($re['ret'] != 0)
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $re['reason']);
                        $re['ret'] = 1;
                        return $re;
                    }
                    else
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_SUCCE, "消息接收成功,等待注入,消息ID[{$message['nns_message_id']}]");
                    }
                }
            }
        }
        //直播频道
        if (!empty($arr_channel))
        {
            //循环频道，对每个频道进行处理
            foreach ($arr_channel as $val_channel)
            {
                //频道删除操作
                if (strtoupper($val_channel['Action']) == 'DELETE')
                {
                    $del_channel = array(
                        'base_info' => array(
                            'nns_import_id' => $val_channel['ContentID'],
                            'nns_import_source' => isset($val_channel['nns_import_source']) ? $val_channel['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->live_action('delete', $del_channel);
                }
                else
                {
                    //1、创建栏目
                    if ($message['nns_cp_id'] == 'JSCN')
                    {
                        $val_channel['key_val_list']['CategoryName'] = (isset($val_channel['key_val_list']['PgmCategory']) && strlen($val_channel['key_val_list']['PgmCategory']) > 0) ? $val_channel['key_val_list']['PgmCategory'] : '卫视频道';
                    }
                    $asset_category = (isset($val_channel['key_val_list']['CategoryName']) && strlen($val_channel['key_val_list']['CategoryName']) > 0) ? $val_channel['key_val_list']['CategoryName'] : '卫视频道';
                    $category_import_id = (isset($val_channel['key_val_list']['CategoryID']) && strlen($val_channel['key_val_list']['CategoryID']) > 0) ? $val_channel['key_val_list']['CategoryID'] : '';
                    $do_category = array(
                        'base_info' => array(
                            'nns_name' => $asset_category,   //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_import_category_id' => $category_import_id, //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_cp_id' => isset($val_channel['key_val_list']['CPContentID']) ? $val_channel['key_val_list']['CPContentID'] : $message['nns_cp_id'],
                            'nns_import_parent_category_id' => '',
                            'nns_video_type' => '1',  //媒资类型  0 点播 | 1 直播
                        ),
                    );
                    $add_category_result = $this->category_action('add', $do_category);
                    if ($add_category_result['ret'] != 0 || !isset($add_category_result['data_info']['base_info']['nns_id']) || strlen($add_category_result['data_info']['base_info']['nns_id']) < 1)
                    {
                        return m_config::return_data(1, '创建栏目失败，失败原因：'.$add_category_result['reason']);
                    }
                    $nns_category_id = $add_category_result['data_info']['base_info']['nns_id'];    //直播频道所属资源库栏目ID
                    //2、处理直播频道海报
                    $arr_img = $this->handle_picture_v3($val_channel['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_channel['key_val_list'] = array_merge($val_channel['key_val_list'], $arr_img);
                    }
                    //3、拼接直播频道添加数组
                    $add_channel = array(
                        'base_info' => array(   //基本信息（存储于nns_live表中）
                            //直播频道名称
                            'nns_name' => isset($val_channel['key_val_list']['Name']) ? $val_channel['key_val_list']['Name'] : '',
                            //直播频道别名
                            'nns_alias_name' => isset($val_channel['key_val_list']['CallSign']) ? $val_channel['key_val_list']['CallSign'] : '',
                            //直播频道类型，0直播频道，1轮播频道，2广播频道，3虚拟频道
                            'nns_view_type' => isset($val_channel['key_val_list']['Type']) ? $val_channel['key_val_list']['Type'] : '0',
                            //直播频道状态，暂时固定为1启用
                            'nns_state' => isset($val_channel['key_val_list']['Status']) ? $val_channel['key_val_list']['Status'] : '1',
                            //直播频道终端EPG标识，默认为26，多个用逗号隔开
                            'nns_tag' => isset($val_channel['key_val_list']['Tags']) ? $val_channel['key_val_list']['Tags'] : '26',
                            //直播频道所属CPID
                            'nns_cp_id' => isset($val_channel['key_val_list']['CPContentID']) ? $val_channel['key_val_list']['CPContentID'] : $message['nns_cp_id'],
                            //直播频道所属资源库栏目ID
                            'nns_category_id' => $nns_category_id,
                            //直播频道简介
                            'nns_summary' => isset($val_channel['key_val_list']['Description']) ? $val_channel['key_val_list']['Description'] : '',
                            //直播频道所属地区
                            'nns_area' => isset($val_channel['key_val_list']['Country']) ? $val_channel['key_val_list']['Country'] : '',
                            //直播频道信号源，默认为1 live；2是virtual
                            'nns_sub_type'=>isset($val_channel['key_val_list']['SubType']) ? $val_channel['key_val_list']['SubType'] : '1',
                            //直播频道语言种类
                            'nns_language' => isset($val_channel['key_val_list']['Language']) ? $val_channel['key_val_list']['Language'] : '',
                            //直播频道有无拷贝保护，默认为1有，0为没有
                            'nns_macrovision' => isset($val_channel['key_val_list']['Macrovision']) ? $val_channel['key_val_list']['Macrovision'] : '1',
                            //直播频道发布到融合平台时队列优先级
                            'nns_hotdegree' => isset($val_channel['key_val_list']['Hotdegree']) ? $val_channel['key_val_list']['Hotdegree'] : '0',
                            //直播频道注入ID
                            'nns_import_id' => $val_channel['ContentID'],
                            'nns_image0' => isset($val_channel['key_val_list']['bigpic']) ? $val_channel['key_val_list']['bigpic'] : '',
                            'nns_image1' => isset($val_channel['key_val_list']['middlepic']) ? $val_channel['key_val_list']['middlepic'] : '',
                            'nns_image2' => isset($val_channel['key_val_list']['smallpic']) ? $val_channel['key_val_list']['smallpic'] : '',
                            'nns_image_v' => isset($val_channel['key_val_list']['verticality_img']) ? $val_channel['key_val_list']['verticality_img'] : '',
                            'nns_image_s' => isset($val_channel['key_val_list']['square_img']) ? $val_channel['key_val_list']['square_img'] : '',
                            'nns_image_h' => isset($val_channel['key_val_list']['horizontal_img']) ? $val_channel['key_val_list']['horizontal_img'] : '',

                            //以下是CMS没有下传过来的数据，做处理
                            'nns_show_time' => (isset($val_channel['key_val_list']['ReleaseYear']) && strlen($val_channel['key_val_list']['ReleaseYear']) > 0) ? date("Y", strtotime($val_channel['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_view_len' => isset($val_channel['key_val_list']['StorageDuration']) ? $val_channel['key_val_list']['StorageDuration'] : 0,
                            'nns_all_index' => isset($val_channel['key_val_list']['VolumnCount']) ? $val_channel['key_val_list']['VolumnCount'] : 1,
                            'nns_new_index' => isset($val_channel['key_val_list']['NewCount']) ? $val_channel['key_val_list']['NewCount'] : 0,
                            'nns_image3' => '',
                            'nns_image4' => '',
                            'nns_image5' => '',
                            'nns_remark' => isset($val_channel['key_val_list']['Kind']) ? $val_channel['key_val_list']['Kind'] : '',
                            'nns_play_count' => '0',
                            'nns_score' => '0',
                            'nns_score_count' => '0',
                            'nns_point' => isset($val_channel['key_val_list']['ViewPoint']) ? $val_channel['key_val_list']['ViewPoint'] : '0',
                            'nns_copyright_date' => (isset($val_channel['key_val_list']['ReleaseYear']) && strlen($val_channel['key_val_list']['ReleaseYear']) > 0) ? date("Y", strtotime($val_channel['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_pinyin' => (isset($val_channel['key_val_list']['Spell']) && strlen($val_channel['key_val_list']['Spell']) > 0) ? $val_channel['key_val_list']['Spell'] : m_pinyin::get_pinyin_letter($val_channel['key_val_list']['Name']),
                            'nns_pinyin_length' => (isset($val_channel['key_val_list']['Spell']) && strlen($val_channel['key_val_list']['Spell']) > 0) ? strlen($val_channel['key_val_list']['Spell']) : strlen(m_pinyin::get_pinyin_letter($val_channel['key_val_list']['Name'])),
                            'nns_eng_name' => isset($val_channel['key_val_list']['EnglishName']) ? $val_channel['key_val_list']['EnglishName'] : '',
                            'nns_producer' => isset($val_channel['key_val_list']['ContentProvider']) ? $val_channel['key_val_list']['ContentProvider'] : '',
                            'nns_import_source' => isset($val_channel['nns_import_source']) ? $val_channel['nns_import_source'] : evn::get("project"),
                            'nns_image_t' => '',
                            'nns_ext_info' => '',
                        ),
                        'ex_info' => array(    //扩展信息（存储于nns_live_ex表中）
                            //直播频道号
                            'live_pindao_order' => isset($val_channel['key_val_list']['ChannelNumber']) ? $val_channel['key_val_list']['ChannelNumber'] : '',
                            //直播频道类型 0：直播，1：时移
                            'live_type' => (isset($val_channel['key_val_list']['TimeShift']) && $val_channel['key_val_list']['TimeShift'] = 1) ? 'TSTV' : 'LIVE',
                            //直播频道回看天数
                            'back_record_day' => isset($val_channel['key_val_list']['StorageDuration']) ? $val_channel['key_val_list']['StorageDuration'] : '0',
                            //直播频道时移时间
                            'ts_default_pos' => isset($val_channel['key_val_list']['TimeShiftDuration']) ? $val_channel['key_val_list']['TimeShiftDuration'] : '',

                            //以下是CMS没有下传过来的数据，做处理
                            'dvb' => isset($val_channel['key_val_list']['DVB']) ? $val_channel['key_val_list']['DVB'] : '',
                            'back_record_day_type' => '',
                            'pid' => isset($val_channel['key_val_list']['PID']) ? $val_channel['key_val_list']['PID'] : np_guid_rand(),
                            'ts_limit_min' => isset($val_channel['key_val_list']['TSMin']) ? $val_channel['key_val_list']['TSMin'] : 0,
                            'ts_limit_max' => isset($val_channel['key_val_list']['TSMax']) ? $val_channel['key_val_list']['TSMax'] : 0,
                        ),
                    );
                    //字段待修改4-14
                    $result = $this->live_action('add', $add_channel);
                }
                if ($result['ret'] != 0)
                {
                    break;
                }
            }
        }
        //直播源
        if (!empty($arr_physical_channel))
        {
            foreach ($arr_physical_channel as $val_live_media)
            {
                //删除直播源
                if (strtoupper($val_live_media['Action']) == 'DELETE')
                {
                    $del_live_media = array(
                        'base_info' => array(
                            'nns_content_id' => $val_live_media['ContentID'],
                            'nns_import_source' => isset($val_live_media['nns_import_source']) ? $val_live_media['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $re = $this->live_media_action('delete', $del_live_media);
                    if ($re['ret'] != 0)
                    {
                        $re['ret'] = 1;
                        return $re;
                    }
                }
                //注入和修改直播源
                else
                {
                    $arr_p_channel = $this->get_map_info_v2('PhysicalChannel', $this->arr_map, $val_live_media['ContentID']);
                    $arr_p_channel = array_keys($arr_p_channel);
                    $res_channel = nl_live::query_by_condition(m_config::get_dc(), array('nns_import_id' => $arr_p_channel[0]));
                    if (!is_array($res_channel['data_info']) || empty($res_channel['data_info']))
                    {
                        //返回频道未注入
                        return $re['ret'] = 10;
                    }
                    $live_id = $res_channel['data_info'][0]['nns_id'];
                    $live_import_id = $arr_p_channel[0];
                    $cp_id = isset($val_channel['key_val_list']['CPContentID']) ? $val_channel['key_val_list']['CPContentID'] : $message['nns_cp_id'];
                    // 模拟创建直播分集
                    $str_index_id = np_guid_rand();
                    $add_live_index = array(
                        'base_info' => array(
                            'nns_name' => $res_channel['data_info'][0]['nns_name'],
                            'nns_index' => 0,
                            'nns_time_len' => 3600,
                            'nns_summary' => '',
                            'nns_image' => '',
                            'nns_play_count' => 0,
                            'nns_score' => 0,
                            'nns_score_count' => 0,
                            'nns_cp_id' => $cp_id,
                            'nns_live_import_id'=>$live_import_id,
                            'nns_import_id' => $live_import_id,         //直播频道分集的注入ID 跟 直播频道的注入ID一致
                            'nns_import_source' => evn::get("project"),
                        ),
                        'hide_info' => array(
                            'nns_id' => $str_index_id,
                            'nns_live_id' => $live_id,
                        )
                    );
                    $result_exist = nl_live_index::query_by_condition(m_config::get_dc(), array('nns_live_id' => $add_live_index['hide_info']['nns_live_id'], 'nns_cp_id' => $cp_id));
                    if (!is_array($result_exist['data_info']) || empty($result_exist['data_info']) || !isset($result_exist['data_info'][0]) || !is_array($result_exist['data_info'][0]) || empty($result_exist['data_info'][0]))
                    {
                        $re = $this->live_index_action('add', $add_live_index);
                        if ($re['ret'] != 0)
                        {
                            $re['ret'] = 1;
                            return $re;
                        }
                    }
                    else
                    {
                        $str_index_id = $result_exist['data_info'][0]['nns_id'];
                    }
                    //直播片源参数
                    $add_live_media = array(
                        'base_info' => array(       //基本信息（存储于nns_live表中）
                            //直播源名称等于直播频道名称
                            'nns_name' => $res_channel['data_info'][0]['nns_name'],
                            //直播源用户访问，是单播还是组播，上游传递multicast、unicast ，在播控unicast=0 表示单播，multicast=1表示组播
                            'nns_cast_type'=>(isset($val_live_media['key_val_list']['DestCastType']) && $val_live_media['key_val_list']['DestCastType'] == 'multicast') ? 1 :  0,
                            //直播源CDN接收到的频道类型方式，可能是单播，也可能是组播。，上游传递multicast、unicast ，在播控unicast=0 表示单播，multicast=1表示组播
                            'nns_cdn_cast_type'=>(isset($val_live_media['key_val_list']['SrcCastType']) && $val_live_media['key_val_list']['DestCastType'] == 'SrcCastType') ? 1 :  0,
                            //直播源EPG终端分组
                            'nns_tag' => isset($val_live_media['key_val_list']['Tags']) ? $val_live_media['key_val_list']['Tags'] : '26',
                            //直播源回看天数，CMS传值跟所属直播频道是一致的。
                            'nns_storage_duration' => isset($val_live_media['key_val_list']['StorageDuration']) ? $val_live_media['key_val_list']['StorageDuration'] : '0',
                            //直播源是否支持时移
                            'nns_timeshift_status' => (isset($val_live_media['key_val_list']['TimeShift']) && $val_live_media['key_val_list']['TimeShift'] =='1' ) ? $val_live_media['key_val_list']['TimeShift'] : '0',
                            //直播源码率，默认为空
                            'nns_kbps' => isset($val_live_media['key_val_list']['BitRateType']) ? $val_live_media['key_val_list']['BitRateType'] : '',
                            //直播源CPID
                            'nns_cp_id' => isset($val_live_media['key_val_list']['CPContentID']) ? $val_live_media['key_val_list']['CPContentID'] : $message['nns_cp_id'],
                            //直播源组播 IP。当SrcCastType为组播时，必填
                            'nns_multiple_cast_ip' => isset($val_live_media['key_val_list']['MultiCastIP']) ? $val_live_media['key_val_list']['MultiCastIP'] : '',
                            //直播源组播端口。当SrcCastType为组播时，必填
                            'nns_multiple_cast_port' => isset($val_live_media['key_val_list']['MultiCastPort']) ? $val_live_media['key_val_list']['MultiCastPort'] : '',
                            //直播源单播地址。当SrcCastType为单播时，必填。
                            'nns_unicast_url' => isset($val_live_media['key_val_list']['UnicastUrl']) ? $val_live_media['key_val_list']['UnicastUrl'] : '',
                            //直播源时移时间，单位秒，CMS传值跟所属直播频道是一致的。
                            'nns_timeshift_delay' => isset($val_live_media['key_val_list']['TimeShiftDuration']) ? $val_live_media['key_val_list']['TimeShiftDuration'] : '0',
                            //直播源分辨率
                            'nns_resolution' => isset($val_live_media['key_val_list']['Resolution']) ? $val_live_media['key_val_list']['Resolution'] : '1920*1080',
                            //直播源文件格式
                            'nns_filetype' => isset($val_live_media['key_val_list']['SystemLayer']) ? $val_live_media['key_val_list']['SystemLayer'] : '',
                            //直播源清晰度
                            'nns_mode' => isset($val_live_media['key_val_list']['VideoProfile']) ? $val_live_media['key_val_list']['VideoProfile'] : '',
                            //直播源发布到融合平台时队列网络域
                            'nns_domain' => isset($val_live_media['key_val_list']['Domain']) ? $val_live_media['key_val_list']['Domain'] : '',
                            //直播源发布到融合平台时队列优先级
                            'nns_hotdegree' => isset($val_live_media['key_val_list']['Hotdegree']) ? $val_live_media['key_val_list']['Hotdegree'] : '',

                            //下面是CMS没有传值的参数
                            'nns_type' => 1,
                            'nns_url' => isset($val_live_media['key_val_list']['Url']) ? $val_live_media['key_val_list']['Url'] : '',
                            'nns_content_id' => $val_live_media['ContentID'],
                            'nns_content_state' => 0,
                            'nns_play_count' => '0',
                            'nns_score_total' => '0',
                            'nns_score_count' => '0',
                            'nns_media_cps' => isset($val_live_media['key_val_list']['MediaCPS']) ? $val_live_media['key_val_list']['MediaCPS'] : 'LIVE',
                            'nns_message_id' => $message['nns_id'],
                            'nns_storage_status' => isset($val_live_media['key_val_list']['StorageStatus']) ? $val_live_media['key_val_list']['StorageStatus'] : 0,
                            'nns_storage_delay' => isset($val_live_media['key_val_list']['StorageDelay']) ? $val_live_media['key_val_list']['StorageDelay'] : 0,
                            'nns_drm_enabled' => isset($val_live_media['key_val_list']['DrmEnabled']) ? $val_live_media['key_val_list']['DrmEnabled'] : 0,
                            'nns_drm_encrypt_solution' => isset($val_live_media['key_val_list']['DrmEncryptSolution']) ? $val_live_media['key_val_list']['DrmEncryptSolution'] : '',
                            'nns_drm_ext_info' => isset($val_live_media['key_val_list']['DrmEncryptExt']) ? $val_live_media['key_val_list']['DrmEncryptExt'] : '',
                            'nns_import_source' => evn::get("project"),
                            'nns_media_service' => isset($val_live_media['key_val_list']['MediaService']) ? $val_live_media['key_val_list']['MediaService'] : 'MSP',
                            'nns_ext_url' => '',
                            'nns_live_import_id' => $live_import_id,
                            'nns_live_index_import_id' => $live_import_id,
                        ),
                        'hide_info' => array(
                            'nns_id' => np_guid_rand(),
                            'nns_state' => isset($val_live_media['key_val_list']['State']) ? $val_live_media['key_val_list']['State'] : 1,
                            'nns_deleted' => 0,
                            'nns_check' => isset($val_live_media['key_val_list']['Check']) ? $val_live_media['key_val_list']['Check'] : 1, 'nns_original_id' => isset($val_channel['key_val_list']['OriginalId']) ? $val_channel['key_val_list']['OriginalId'] : '',
                            'nns_live_id' => $str_index_id,
                        ),
                    );
                    $re = $this->live_media_action('add', $add_live_media);

                    if ($re['ret'] != 0)
                    {
                        $re['ret'] = 1;
                    }
                    return $re;
                }
            }
        }
        //直播节目单
        if (!empty($arr_schedule_record))
        {
            //循环节目单，对每个节目单进行处理
            foreach ($arr_schedule_record as $val_playbill)
            {
                //频道删除操作
                if (strtoupper($val_playbill['Action']) == 'DELETE')
                {
                    $del_playbill = array(
                        'base_info' => array(
                            'nns_playbill_import_id' => $val_playbill['ContentID'],
                            'nns_import_source' => isset($val_playbill['nns_import_source']) ? $val_playbill['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->playbill_action('delete', $del_playbill);
                } //节目单更新或者注入
                else
                {
                    $arr_p_series = $this->get_map_info_v2('ScheduleRecord', $this->arr_map, $val_playbill['ContentID']);
                    $p_series = array_keys($arr_p_series);
                    $p_series[0];//直播频道ID
                    $arr_img = $this->handle_picture_v3($val_playbill['ContentID']);

                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_playbill['key_val_list'] = array_merge($val_playbill['key_val_list'], $arr_img);
                    }

                    $pinyin = m_pinyin::get_pinyin_letter($val_playbill['key_val_list']['Name']);
                    //开始时间
                    $start_date = isset($val_playbill['key_val_list']['StartDate']) ? $val_playbill['key_val_list']['StartDate'] : date('Ymd');
                    $start_time = isset($val_playbill['key_val_list']['StartTime']) ? $val_playbill['key_val_list']['StartTime'] : date('His');
                    $begin_time = $start_date . " " . $start_time;
                    $begin_time = date('Y-m-d H:i:s', strtotime($begin_time));
                    $time_len = isset($val_playbill['key_val_list']['Duration']) ? $val_playbill['key_val_list']['Duration'] : 0;
                    $end_time = isset($val_playbill['key_val_list']['EndTime']) ? $val_playbill['key_val_list']['EndTime'] : (int)$start_time + (int)$time_len;
                    $end_time = $start_date . " " . $end_time;
                    $end_time = date('Y-m-d H:i:s', strtotime($end_time));
                    $add_playbill = array(
                        'base_info' => array(
                            //节目单名称
                            'nns_name' => isset($val_playbill['key_val_list']['Name']) ? $val_playbill['key_val_list']['Name'] : '',
                            'nns_view_type' => 1,
                            //节目单开始时间
                            'nns_begin_time' => $begin_time,
                            //节目单结束时间
                            'nns_end_time' => $end_time,
                            //节目单时长
                            'nns_time_len' => isset($val_playbill['key_val_list']['Duration']) ? $val_playbill['key_val_list']['Duration'] : 0,
                            //节目单CPID
                            'nns_cp_id' => isset($val_playbill['key_val_list']['CPContentID']) ? $val_playbill['key_val_list']['CPContentID'] : $message['nns_cp_id'],
                            //节目单简介
                            'nns_summary' => isset($val_playbill['key_val_list']['Description']) ? $val_playbill['key_val_list']['Description'] : '',
                            //节目单上游注入网络域
                            'nns_domain' => isset($val_playbill['key_val_list']['Domain']) ? $val_playbill['key_val_list']['Domain'] : '',
                            //节目单发布到融合平台时队列优先级
                            'nns_hot_dgree' => isset($val_playbill['key_val_list']['HotDgree']) ? $val_playbill['key_val_list']['HotDgree'] : 0,
                            //节目单注入ID
                            'nns_playbill_import_id' => $val_playbill['ContentID'],
                            //注入来源
                            'nns_import_source' => evn::get("project"),
                            //直播频道注入ID
                            'nns_live_id'=>$p_series[0],

                            'nns_image0' => isset($val_playbill['key_val_list']['bigpic']) ? $val_playbill['key_val_list']['bigpic'] : '',
                            'nns_image1' => isset($val_playbill['key_val_list']['middlepic']) ? $val_playbill['key_val_list']['middlepic'] : '',
                            'nns_image2' => isset($val_playbill['key_val_list']['smallpic']) ? $val_playbill['key_val_list']['smallpic'] : '',
                            'nns_image3' => '',
                            'nns_image4' => '',
                            'nns_image5' => '',
                            'nns_pinyin' => (isset($val_playbill['key_val_list']['Spell']) && strlen($val_playbill['key_val_list']['Spell']) > 0) ? $val_playbill['key_val_list']['Spell'] : $pinyin,
                            'nns_pinyin_length' => (isset($val_playbill['key_val_list']['Spell']) && strlen($val_playbill['key_val_list']['Spell']) > 0) ? strlen($val_playbill['key_val_list']['Spell']) : strlen($pinyin),
                            'nns_eng_name' => isset($val_playbill['key_val_list']['EnglishName']) ? $val_playbill['key_val_list']['EnglishName'] : '',
                            'nns_keyword' => isset($val_playbill['key_val_list']['Keyword']) ? $val_playbill['key_val_list']['Keyword'] : '',
                            'nns_kind' => isset($val_playbill['key_val_list']['Kind']) ? $val_playbill['key_val_list']['Kind'] : '',
                            'nns_actor' => isset($val_playbill['key_val_list']['ActorDisplay']) ? $val_playbill['key_val_list']['ActorDisplay'] : '',
                            'nns_director' => isset($val_playbill['key_val_list']['WriterDisplay']) ? $val_playbill['key_val_list']['WriterDisplay'] : '',
                            'nns_ext_url' => '',
                            'nns_image_v' => isset($val_playbill['key_val_list']['verticality_img']) ? $val_playbill['key_val_list']['verticality_img'] : '',
                            'nns_image_h' => isset($val_playbill['key_val_list']['horizontal_img']) ? $val_playbill['key_val_list']['horizontal_img'] : '',
                            'nns_image_s' => isset($val_playbill['key_val_list']['square_img']) ? $val_playbill['key_val_list']['square_img'] : '',
                        ),
                        //基本信息（存储于nns_live_playbill_item表中）
                        'hide_info' => array(
                            'nns_state' => isset($val_playbill['key_val_list']['State']) ? $val_playbill['key_val_list']['State'] : 1,
                            'nns_deleted' => 0,
                            'nns_check' => isset($val_playbill['key_val_list']['Check']) ? $val_playbill['key_val_list']['Check'] : 1,
                        )
                    );
                    //字段待修改4-14
                    $result = $this->playbill_action('add', $add_playbill);
                }
                if ($result['ret'] != 0)
                {
                    break;
                }
            }
        }
        //打点信息注入
        if(!empty($arr_seekpoint))
        {
            //循环打点信息
            foreach($arr_seekpoint as $val_seekpoint)
            {
                //删除打点信息
                if(strtoupper($val_seekpoint['Action']) == 'DELETE')
                {
                    $del_seekpoint = array(
                        'base_info'=>array(
                            'nns_import_id' => $val_seekpoint['ContentID'],
                            'nns_import_source' => isset($val_playbill['nns_import_source']) ? $val_playbill['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->seekpoint_action('delete', $del_seekpoint);
                }
                //打点信息更新或者注入
                else
                {
                    $arr_img = $this->handle_picture_v3($val_seekpoint['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_seekpoint['key_val_list'] = array_merge($val_seekpoint['key_val_list'], $arr_img);
                    }
                    if($val_seekpoint['key_val_list']['FragmentType']=='head')
                    {
                        $FragmentType=1;
                    }
                    if($val_seekpoint['key_val_list']['FragmentType']=='medium')
                    {
                        $FragmentType=0;
                    }
                    if($val_seekpoint['key_val_list']['FragmentType']=='end')
                    {
                        $FragmentType=2;
                    }
                    if($val_seekpoint['key_val_list']['FragmentType']=='interact')
                    {
                        $FragmentType=3;
                    }
                    if(!empty($val_seekpoint['key_val_list']['Type']))
                    {
                        (substr($val_seekpoint['key_val_list']['Type'],0)=='1')? $Type=1 :$Type=0;
                    }
                    $add_seekpoint = array(
                        'base_info' => array(
                            'nns_video_index'=>isset($val_seekpoint['key_val_list']['Sequence'])?$val_seekpoint['key_val_list']['Sequence'] : 0,
                            'nns_vod_index_id'=>$val_seekpoint['key_val_list']['ProgramID'],
                            'nns_fragment_type'=>isset($FragmentType)?$FragmentType : 0,
                            'nns_type'=>isset($Type) ? $Type:0,
                            'nns_image'=>isset($val_seekpoint['key_val_list']['bigpic'])? $val_seekpoint['key_val_list']['bigpic']:'',
                            'nns_begin'=>isset($val_seekpoint['key_val_list']['BeginTime'])?$val_seekpoint['key_val_list']['BeginTime'] : 0,
                            'nns_end'=>isset($val_seekpoint['key_val_list']['EndTime'])?$val_seekpoint['key_val_list']['EndTime'] : 0,
                            'nns_name'=>isset($val_seekpoint['key_val_list']['Name'])?$val_seekpoint['key_val_list']['Name'] : '',
                            'nns_import_id'=>$val_seekpoint['ContentID'],
                            'nns_import_source'=>isset($val_playbill['nns_import_source']) ? $val_playbill['nns_import_source'] : evn::get("project"),
                            'nns_cp_id'=>$message['nns_cp_id'],
                        ),
                    );
                    $result = $this->seekpoint_action('add', $add_seekpoint);
                }
                if($result['ret'] != 0)
                {
                    break;
                }
            }

        }
        //明星库注入
        if (!empty($arr_actor))
        {
            foreach ($arr_actor as $val_actor)
            {
                //主媒资删除
                if (strtoupper($val_actor['Action']) == 'DELETE')
                {
                    $del_actor = array(
                        'base_info'=>array(
                            'nns_import_id'=>$val_actor['ContentID'],
                            'nns_import_source'=>$val_actor['nns_import_source'],
                            'nns_cp_id'=>$message['nns_cp_id'],
                        ),
                    );
                    $result = $this->actor_action('delete', $del_actor);
                }
                else
                {
                    #TODO
                    $arr_img = $this->handle_picture_v3($val_actor['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_series['key_val_list'] = array_merge($val_actor['key_val_list'], $arr_img);
                    }
                    $pinyin = m_pinyin::get_pinyin_letter($val_actor['key_val_list']['Name']);
                    $ex_info =  array(
                        'constellation' => isset($val_actor['key_val_list']['Constellation']) ? $val_actor['key_val_list']['Constellation'] : '',
                        'college' => isset($val_actor['key_val_list']['College']) ? $val_actor['key_val_list']['College'] : '',
                        'weight' => isset($val_actor['key_val_list']['Weight']) ? $val_actor['key_val_list']['Weight'] : '',
                        'birthplace' => isset($val_actor['key_val_list']['Hometown']) ? $val_actor['key_val_list']['Hometown'] : '',
                        'bloodtype' => isset($val_actor['key_val_list']['BloodGroup']) ? $val_actor['key_val_list']['BloodGroup'] : '',
                        'height' => isset($val_actor['key_val_list']['Height']) ? $val_actor['key_val_list']['Height'] : '',
                        'introduction' => isset($val_actor['key_val_list']['Description']) ? $val_actor['key_val_list']['Description'] : '',
                        'birthday' => isset($val_actor['key_val_list']['Birthday']) ? date('Y-m-d', strtotime($val_actor['key_val_list']['Birthday'])) : '',
                        'story' => isset($val_actor['key_val_list']['story']) ? $val_actor['key_val_list']['story'] : '',
                    );
                    $ex_info = json_encode($ex_info,JSON_UNESCAPED_UNICODE);
                    $add_actor = array(
                        'base_info' => array(
                            'nns_name' => isset($val_actor['key_val_list']['Name']) ? $val_actor['key_val_list']['Name'] : '',
                            'nns_area' => isset($val_actor['key_val_list']['OriginalCountry']) ? $val_actor['key_val_list']['OriginalCountry'] : '',
                            'nns_alias_name' => isset($val_actor['key_val_list']['AliasName']) ? $val_actor['key_val_list']['AliasName'] : '',
                            'nns_profession' => isset($val_actor['key_val_list']['Profession']) ? $val_actor['key_val_list']['Profession'] : '',
                            'nns_pinyin' => (isset($val_actor['key_val_list']['Spell']) && strlen($val_actor['key_val_list']['Spell']) > 0) ? $val_actor['key_val_list']['Spell'] : $pinyin,
                            'nns_works' => isset($val_actor['key_val_list']['Works']) ? $val_actor['key_val_list']['Works'] : 0,
                            'nns_label_id' => isset($val_actor['key_val_list']['LabelID']) ? $val_actor['key_val_list']['LabelID'] : 0,
                            'nns_image_v' => isset($val_actor['key_val_list']['verticality_img']) ? $val_actor['key_val_list']['verticality_img'] : '',
                            'nns_image_s' => isset($val_actor['key_val_list']['square_img']) ? $val_actor['key_val_list']['square_img'] : '',
                            'nns_image_h' => isset($val_actor['key_val_list']['horizontal_img']) ? $val_actor['key_val_list']['horizontal_img'] : '',
                            'nns_old_name' => '',
                            'nns_info' => $ex_info,
                            'nns_english_name' => isset($val_actor['key_val_list']['EnglishName']) ? $val_actor['key_val_list']['EnglishName'] : '',
                            'nns_county' => isset($val_actor['key_val_list']['County']) ? $val_actor['key_val_list']['County'] : '',
                            'nns_sex' => (isset($val_actor['key_val_list']['Sex']) && $val_actor['key_val_list']['Sex'] == 1) ? '男' : '女',
                            'nns_import_id' => $val_actor['ContentID'],
                            'nns_import_source' => isset($val_actor['nns_import_source']) ? $val_actor['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                            ''
                        ), //基本信息（存储于nns_actor表中）
                        'ex_info' => array(), //扩展信息（存储于nns_actor_ex表中）
                    );
                    //字段待修改4-14
                    $result = $this->actor_action('add', $add_actor);
                }
                if($result['ret'] !=0)
                {
                    $result['ret'] = 1;
                    return $result;
                }
            }
        }
        //主媒资上下线
        if (!empty($this->arr_map) && is_array($this->arr_map))
        {
            foreach ($this->arr_map as $map)
            {
                $map_children = $map['children'];
                $map = $map['attributes'];
                if ($map['ElementType'] == 'Category')
                {
                    //此时是上下线
                    //消息操作指令:1添加2修改3删除,4上线,5下线
                    $action = null;
                    if ($map['Action'] == 'DELETE')
                    {
                        $action = 5;
                    }
                    else
                    {
                        $action = 4;
                    }
                    //注入ID
                    $asset_id = $map['ElementID'];
                    //栏目ID
                    $content = array();
                    $content['category_id'] = $map['ParentID'];
                    $content['cp_id'] = isset($message['nns_cp_id']) ? $message['nns_cp_id'] : 0;
                    $content['action'] = $action;
                    $asset_type = 4;
                    if ($map['ElementType'] == 'Program')
                    {
                        $asset_type = 5;
                        if ($message['nns_cp_id'] == 'CNTV' || $message['nns_cp_id'] == 'YANHUAAMS' || $message['nns_cp_id'] == 'CIBN')
                        {
                            //说明是影片，需要转换成自身生成的主媒资ID
                            $asset_id = substr_replace($asset_id, '00100', 0, 5);
                        }
                    }
                    //上下线主媒资名称
                    $ElementName = null;
                    $Sequence = 0;
                    if (is_array($map_children))
                    {
                        foreach ($map_children as $pro)
                        {
                            if ($pro['attributes']['Name'] == 'ElementName')
                            {
                                $ElementName = $pro['content'];
                            }
                            if ($pro['attributes']['Name'] == 'Sequence')
                            {
                                $Sequence = $pro['content'];
                            }
                        }
                    }
                    $content['order'] = $Sequence;
                    $content['message_id'] = $message['nns_id'];
                    $result = $this->line_asset($content, $asset_id);
                    if ($result['ret'] != 0)
                    {
                        $result['ret'] = 1;
                        return $result;
                    }
                    return $result;
                }

            }
        }
        //epg分组
        if (!empty($this->arr_epg_file_set))
        {
            foreach ($this->arr_epg_file_set as $val_epg_file_set)
            {

                if (strtoupper($val_epg_file_set['Action']) == 'DELETE')
                {//删除
                    $del_epg_file_set = array(
                        'base_info' => array(
                            'nns_import_id' => $val_epg_file_set['ContentID'],
                            'nns_group' => $val_epg_file_set['key_val_list']['EPGGroup'],
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->epg_file_set_action('delete', $del_epg_file_set);
                }
                else
                {
                    $add_epg_file_set = array(
                        'base_info' => array(
                            'nns_group' => isset($val_epg_file_set['key_val_list']['EPGGroup']) ? $val_epg_file_set['key_val_list']['EPGGroup'] : '',
                            'nns_import_id' => $val_epg_file_set['ContentID'],
                            'nns_system_file' => isset($val_epg_file_set['key_val_list']['SystemFile']) ? $val_epg_file_set['key_val_list']['SystemFile'] : 0,
                            'nns_tar' => isset($val_epg_file_set['key_val_list']['NeedUnTar']) ? $val_epg_file_set['key_val_list']['NeedUnTar'] : 0,
                            'nns_show_time' => (isset($val_epg_file_set['key_val_list']['BeginTime']) && strlen($val_epg_file_set['key_val_list']['BeginTime']) > 0) ? date("Y-m-d H:i:s", strtotime($val_epg_file_set['key_val_list']['BeginTime'])) : '0000-00-00 00:00:00',
                            'nns_epg_addr' => isset($val_epg_file_set['key_val_list']['EPGAddr']) ? $val_epg_file_set['key_val_list']['EPGAddr'] : '',
                            'nns_cp_id' => $message['nns_cp_id'],
                        ), //基本信息（存储于nns_vod表中）
                    );
                    //字段待修改4-14
                    $result = $this->epg_file_set_action('add', $add_epg_file_set);
                }

                if ($result['ret'] != 0)
                {
                    $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $result['reason']);
                    return $result;
                }
            }
        }
        //epg包
        if (!empty($this->arr_epg_file))
        {
            foreach ($this->arr_epg_file as $val_epg_file)
            {
                if (strtoupper($val_epg_file['Action']) == 'DELETE')
                {//删除
                    $del_epg_file_set = array(
                        'base_info' => array(
                            'nns_import_id' => $val_epg_file['ContentID'],
                            'nns_group' => $val_epg_file['key_val_list']['EPGGroup'],
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->epg_file_action('delete', $del_epg_file_set);
                }
                else
                {
                    $add_epg_file = array(
                        'base_info' => array(
                            'nns_epg_file_set_import_id' => isset($this->arr_epg_file_set[0]['ContentID']) ? $this->arr_epg_file_set[0]['ContentID'] : '',
                            'nns_import_id' => $val_epg_file['ContentID'],
                            'nns_url' => isset($val_epg_file['key_val_list']['SourceUrl']) ? $val_epg_file['key_val_list']['SourceUrl'] : '',
                            'nns_dest_path' => isset($val_epg_file['key_val_list']['DestPath']) ? $val_epg_file['key_val_list']['DestPath'] : '',
                            'nns_dest_file' => isset($val_epg_file['key_val_list']['DestFile']) ? $val_epg_file['key_val_list']['DestFile'] : '',
                            'nns_md5' => isset($val_epg_file['key_val_list']['MD5']) ? $val_epg_file['key_val_list']['MD5'] : '',
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    //字段待修改4-14
                    $result = $this->epg_file_action('add', $add_epg_file);
                }

                if ($result['ret'] != 0)
                {
                    $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],原因" . $result['reason']);
                    return $result;
                }
            }
        }
        return m_config::return_data(0, "消息注入成功");
    }

    public function parse_xml($message,$arr_message_data)
    {
        //1、属性赋值
        $this->str_message_id = $message['nns_message_id'];
        $this->csp_data['CorrelateID'] = $message['nns_message_id'];
        //2、获取媒资注入ID
        if (!is_array($arr_message_data['data']['children']) || empty($arr_message_data['data']['children']))
        {
            return $this->_create_result(1, '消息内容中数据为空');
        }
        $arr_request_list = np_array_rekey($arr_message_data['data']['children'], 'name');
        if (!is_array($arr_request_list['ContentInfo']) || empty($arr_request_list['ContentInfo']))
        {

            return $this->_create_result(1, '消息内容中ContentInfo节点数据为空');
        }
        $arr_content_info = np_array_rekey($arr_request_list['ContentInfo']['children'], 'name');
        if (!isset($arr_content_info['ContentGUID']['content']) || strlen($arr_content_info['ContentGUID']['content']) == 0)
        {
            return $this->_create_result(1, '消息内容中ContentGUID为空');
        }
        $str_import_id = $arr_content_info['ContentGUID']['content'];
        //3、处理实体文件信息数据
        $arr_file_info_list = array();
        if (is_array($arr_content_info['ContentFile']['children']) && !empty($arr_content_info['ContentFile']['children']))
        {
            $arr_file_item_list = $arr_content_info['ContentFile']['children'];
            foreach ($arr_file_item_list as $arr_file_item)
            {
                // 处理实体文件信息
                $arr_file_item = np_array_rekey($arr_file_item['children'], 'name');
                $arr_tmp_info = array(
                    'file_id'       => $arr_file_item['FileID']['content'],
                    'file_type'         => '',
                    'file_name'         => '',
                    'file_path'         => '',
                    'file_definition'   => 'std',
                    'file_resolution'   => '',
                    'file_size'         => '',
                    'file_bit_rate'     => '',
                    'file_coding'       => '',
                    'file_desc'         => '',
                    'file_time_len'     => '',
                    'FrameRate'         => '',
                    'file_hash'         => '',
                    'file_width'        => '',
                    'file_height'       => '',
                    'file_scale'        => '',
                    'asset_source'      => $message['nns_cp_id'],
                    'import_source'     => '',
                    'file_3d'           => '',
                    'file_3d_type'      => ''
                );
                // 处理视频码率格式，示例为：H264_8000K_MP4，对应为：编码格式_视频码率_文件格式
                if (isset($arr_file_item['FileTypeID']['content']) && strlen($arr_file_item['FileTypeID']['content']) > 0)
                {
                    $arr_file_type_info = explode('_', $arr_file_item['FileTypeID']['content']);
                    if (isset($arr_file_type_info[0]) && strlen($arr_file_type_info[0]) > 0)
                    {
                        $arr_tmp_info['file_coding'] = $arr_file_type_info[0];
                    }
                    if (isset($arr_file_type_info[1]) && strlen($arr_file_type_info[1]) > 0)
                    {
                        $arr_tmp_info['file_bit_rate'] = rtrim($arr_file_type_info[1], 'K');
                    }
                    if (isset($arr_file_type_info[2]) && strlen($arr_file_type_info[2]) > 0)
                    {
                        $arr_tmp_info['file_type'] = strtolower($arr_file_type_info[2]);
                    }
                }
                // 处理片源文件路径
                if (isset($arr_file_item['FileName']['content']) && strlen($arr_file_item['FileName']['content']) > 0)
                {
                    $arr_tmp_info['file_path'] = $arr_file_item['FileName']['content'];
                }
                // 处理片源清晰度
                if (isset($arr_file_item['QualityType']['content']) && strlen($arr_file_item['QualityType']['content']) > 0)
                {
                    if (isset($this->arr_file_definition_map[$arr_file_item['QualityType']['content']])) {
                        $arr_tmp_info['file_definition'] = $this->arr_file_definition_map[$arr_file_item['QualityType']['content']];
                    }
                }
                // 处理文件大小，上游给的文件大小的单位是：b，需要转换为我们系统的单位：M
                if (isset($arr_file_item['FileSize']['content']) && strlen($arr_file_item['FileSize']['content']) > 0)
                {
                    $arr_tmp_info['file_size'] = round($arr_file_item['FileSize']['content'] / 1024 / 1024, 2);
                }
                // 处理音视频信息
                if (is_array($arr_file_item['FileFormat']['children']) && !empty($arr_file_item['FileFormat']['children']))
                {
                    $arr_file_format_info = np_array_rekey($arr_file_item['FileFormat']['children'], 'name');
                    if (is_array($arr_file_format_info['VideoFormat']['children'])
                        && !empty($arr_file_format_info['VideoFormat']['children']))
                    {
                        // 处理视频信息
                        $arr_video_format_info = np_array_rekey($arr_file_format_info['VideoFormat']['children'], 'name');

                        // 处理视频分辨率
                        if (isset($arr_video_format_info['ImageWidth']['content'])
                            && strlen($arr_video_format_info['ImageWidth']['content']) > 0
                            && isset($arr_video_format_info['ImageHeight']['content'])
                            && strlen($arr_video_format_info['ImageHeight']['content']) > 0)
                        {
                            $arr_tmp_info['file_resolution'] = $arr_video_format_info['ImageWidth']['content']
                                . '*' . $arr_video_format_info['ImageHeight']['content'];
                        }
                        // 处理视频帧率
                        if (isset($arr_video_format_info['FrameRate']['content'])
                            && strlen($arr_video_format_info['FrameRate']['content']) > 0)
                        {
                            $arr_tmp_info['FrameRate'] = $arr_video_format_info['FrameRate']['content'];
                        }
                    }
                }
                // 组装文件列表数据
                $arr_file_info_list[] = $arr_tmp_info;
            }
        }
        //4、初始化主媒资和分集信息
        $arr_assets_info = array(
            'assets_category'       => '电影',
            'view_type'             => 0,
            'name'                  => '',
            'sreach_key'            => '',
            'director'              => '',
            'player'                => '',
            'tag'                   => '',
            'region'                => '',
            'release_time'          => '',
            'totalnum'              => 1,
            'national'              => '',
            'smallpic'              => '',
            'middlepic'             => '',
            'bigpic'                => '',
            'verticality_img'       => '',
            'horizontal_img'        => '',
            'square_img'            => '',
            'intro'                 => '',
            'producer'              => '',
            'adaptor'               => '',
            'english_name'          => '',
            'subordinate_name'      => '',
            'caption_language'      => '',
            'play_role'             => '',
            'initials'              => '',
            'view_len'              => '',
            'offline_play_support'  => '',
            'language'              => '',
            'asset_source'          => $message['nns_cp_id'],
            'import_source'         => '',
            'online_identify'       => ''
        );
        $arr_clip_info = array(
            'name'                  => '',
            'index'                 => 0,
            'time_len'              => '',
            'summary'               => '',
            'director'              => '',
            'player'                => '',
            'update_time'           => '',
            'release_time'          => '',
            'isintact'              => 1,
            'watch_focus'           => '',
            'subordinate_name'      => '',
            'sort_name'             => '',
            'initials'              => '',
            'publisher'             => '',
            'first_spell'           => '',
            'caption_language'      => '',
            'language'              => '',
            'region'                => '',
            'adaptor'               => '',
            'sreach_key'            => '',
            'event_tag'             => '',
            'year'                  => '',
            'pic'                   => '',
            'asset_source'          => $message['nns_cp_id'],
            'import_source'         => ''
        );
        //6、处理节目海报数据
        if (is_array($arr_content_info['ItemPicFile']['children']) && !empty($arr_content_info['ItemPicFile']['children']))
        {
            foreach ($arr_content_info['ItemPicFile']['children'] as $arr_picture_item)
            {
                // 海报信息为空，跳过
                if (!is_array($arr_picture_item['children']) || empty($arr_picture_item['children']))
                {
                    continue;
                }
                // 根据类型处理海报信息
                $arr_picture_item = np_array_rekey($arr_picture_item['children'], 'name');
                if (!isset($arr_picture_item['Type']['content']) || strlen($arr_picture_item['Type']['content']) == 0
                    || !isset($arr_picture_item['ContentPicName']['content']) || strlen($arr_picture_item['ContentPicName']['content']) == 0)
                {
                    continue;
                }
                $str_img_url = $arr_picture_item['ContentPicName']['content'];
                $temp_img_url = explode(':',$str_img_url,2);
                $cp_config = nl_cp::get_cp_config(m_config::get_dc(),$message['nns_cp_id']);
                $ftp_url = $cp_config['data_info']['nns_config']['down_url_real'];
                $str_img_url = $ftp_url.ltrim($temp_img_url[1],"/");
                switch ($arr_picture_item['Type']['content'])
                {
                    // 海报，转换为主媒资的竖图和分集的海报
                    case 'poster':
                        $arr_assets_info['verticality_img'] = $str_img_url;
                        $arr_clip_info['pic'] = $str_img_url;
                        break;
                    // 缩略图，转换为主媒资的中图
                    case 'thumbnail':
                        $arr_assets_info['middlepic'] = $str_img_url;
                        break;
                    // 剧照，转换为主媒资的大图
                    case 'stills':
                        $arr_assets_info['bigpic'] = $str_img_url;
                        break;
                    // 图标，转换为主媒资的小图
                    case 'icon':
                        $arr_assets_info['smallpic'] = $str_img_url;
                        break;
                    default:
                        break;
                }
            }
        }
        //7、处理节目编目元数据
        $str_import_source = '';
        if (is_array($arr_content_info['ItemCatalog']['children']) && !empty($arr_content_info['ItemCatalog']['children']))
        {
            foreach ($arr_content_info['ItemCatalog']['children'] as $arr_catelog_item)
            {
                // 如果编目信息为空，跳过
                if (!is_array($arr_catelog_item['children']) || empty($arr_catelog_item['children']))
                {
                    continue;
                }
                // 获取属性列表
                $arr_catelog_item = np_array_rekey($arr_catelog_item['children'], 'name');
                if (!isset($arr_catelog_item['ItemCatalogAttribute']['content'])
                    || strlen($arr_catelog_item['ItemCatalogAttribute']['content']) == 0
                    || !isset($arr_catelog_item['ItemAttributes']['children'])
                    || !is_array($arr_catelog_item['ItemAttributes']['children'])
                    || empty($arr_catelog_item['ItemAttributes']['children']))
                {
                    continue;
                }
                $str_catelog_type = $arr_catelog_item['ItemCatalogAttribute']['content'];
                $arr_attribute_list = array();
                foreach ($arr_catelog_item['ItemAttributes']['children'] as $arr_attribute_item)
                {
                    // 如果属性为空，跳过
                    if (!is_array($arr_attribute_item['children']) || empty($arr_attribute_item['children']))
                    {
                        continue;
                    }

                    // 获取属性信息
                    $arr_attribute_item = np_array_rekey($arr_attribute_item['children'], 'name');
                    if (!isset($arr_attribute_item['Code']['content']) || strlen($arr_attribute_item['Code']['content']) == 0
                        || !isset($arr_attribute_item['Values']['content']) || strlen($arr_attribute_item['Values']['content']) == 0)
                    {
                        continue;
                    }
                    $arr_attribute_list[$arr_attribute_item['Code']['content']] = trim($arr_attribute_item['Values']['content']);
                }
                // 根据不同的编目信息类型处理编目信息
                switch ($str_catelog_type)
                {
                    // 媒资元数据编目
                    case 'Metadata':
                        // 影片名称
                        if (isset($arr_attribute_list['Title']) && strlen($arr_attribute_list['Title']) > 0)
                        {
                            $str_assets_name = htmlspecialchars($arr_attribute_list['Title'], ENT_QUOTES);
                            $str_assets_name_pinyin =nl_pinyin::get_pinyin_letter($str_assets_name);
                            $arr_assets_info['name'] = $str_assets_name;
                            $arr_assets_info['initials'] = $str_assets_name_pinyin;
                            $arr_clip_info['name'] = $str_assets_name;
                            $arr_clip_info['initials'] = $str_assets_name_pinyin;
                            $arr_clip_info['first_spell'] = $str_assets_name_pinyin;
                        }
                        // 影片种类，生成影片所属资源库栏目和影片种类view_type
                        if (isset($arr_attribute_list['shootCatagory']) && strlen($arr_attribute_list['shootCatagory']) > 0)
                        {
                            $str_assets_category = htmlspecialchars($arr_attribute_list['shootCatagory'], ENT_QUOTES);
                            $arr_assets_info['assets_category'] = $str_assets_category;
                            foreach ($this->category_map as $int_view_type => $str_view_type_name)
                            {
                                if (stripos($str_view_type_name, $str_assets_category) !== false)
                                {
                                    $arr_assets_info['view_type'] = $int_view_type;
                                    break;
                                }
                            }
                        }
                        // 影片类型
                        if (isset($arr_attribute_list['propertyType']) && strlen($arr_attribute_list['propertyType']) > 0)
                        {
                            $arr_assets_info['tag'] = htmlspecialchars($arr_attribute_list['propertyType'], ENT_QUOTES);
                        }
                        // 别名
                        if (isset($arr_attribute_list['otherTitle']) && strlen($arr_attribute_list['otherTitle']) > 0)
                        {
                            $str_alias = htmlspecialchars($arr_attribute_list['otherTitle'], ENT_QUOTES);
                            $arr_assets_info['subordinate_name'] = $str_alias;
                            $arr_clip_info['subordinate_name'] = $str_alias;
                        }
                        // 内容提供商ID
                        if (isset($arr_attribute_list['SourceSystemID']) && strlen($arr_attribute_list['SourceSystemID']) > 0)
                        {
                            $str_original_cp_id = $arr_attribute_list['SourceSystemID'];
                            $arr_assets_info['producer'] = $str_original_cp_id;
                        }
                        // 来源名称
                        if (isset($arr_attribute_list['CreatorName']) && strlen($arr_attribute_list['CreatorName']) > 0)
                        {
                            $str_import_source = htmlspecialchars($arr_attribute_list['CreatorName'], ENT_QUOTES);
                            $arr_assets_info['import_source'] = $str_import_source;
                            $arr_clip_info['import_source'] = $str_import_source;
                        }
                        // 关键字
                        if (isset($arr_attribute_list['Tag']) && strlen($arr_attribute_list['Tag']) > 0)
                        {
                            $str_search_key = htmlspecialchars($arr_attribute_list['Tag'], ENT_QUOTES);
                            $arr_assets_info['sreach_key'] = $str_search_key;
                            $arr_clip_info['sreach_key'] = $str_search_key;
                        }
                        // 简介
                        if (isset($arr_attribute_list['Description']) && strlen($arr_attribute_list['Description']) > 0)
                        {
                            $str_desc = htmlspecialchars($arr_attribute_list['Description'], ENT_QUOTES);
                            $arr_assets_info['intro'] = $str_desc;
                            $arr_clip_info['summary'] = $str_desc;
                        }
                        // 导演
                        if (isset($arr_attribute_list['Director']) && strlen($arr_attribute_list['Director']) > 0)
                        {
                            $str_director = str_replace($this->arr_symbols, '|', $arr_attribute_list['Director']);
                            $str_director = htmlspecialchars($str_director, ENT_QUOTES);
                            $arr_assets_info['director'] = $str_director;
                            $arr_clip_info['director'] = $str_director;
                        }
                        // 演员
                        if (isset($arr_attribute_list['mainPlayer']) && strlen($arr_attribute_list['mainPlayer']) > 0)
                        {
                            $str_player = str_replace($this->arr_symbols, '|', $arr_attribute_list['mainPlayer']);
                            $str_player = htmlspecialchars($str_player, ENT_QUOTES);
                            $arr_assets_info['player'] = $str_player;
                            $arr_clip_info['player'] = $str_player;
                        }
                        // 字幕语种
                        if (isset($arr_attribute_list['captionLanague']) && strlen($arr_attribute_list['captionLanague']) > 0)
                        {
                            $str_caption_language = htmlspecialchars($arr_attribute_list['captionLanague'], ENT_QUOTES);
                            $arr_assets_info['caption_language'] = $str_caption_language;
                            $arr_clip_info['caption_language'] = $str_caption_language;
                        }
                        // 视频语种
                        if (isset($arr_attribute_list['dubbingLanague']) && strlen($arr_attribute_list['dubbingLanague']) > 0)
                        {
                            $str_language = htmlspecialchars($arr_attribute_list['dubbingLanague'], ENT_QUOTES);
                            $arr_assets_info['language'] = $str_language;
                            $arr_clip_info['language'] = $str_language;
                        }
                        // 影片时长，示例为：01:20:00
                        if (isset($arr_attribute_list['ProgramLength']) && strlen($arr_attribute_list['ProgramLength']) > 0)
                        {
                            $int_view_len = strtotime($arr_attribute_list['ProgramLength']) - strtotime('today');
                            $arr_assets_info['view_len'] = $int_view_len;
                            $arr_clip_info['time_len'] = $int_view_len;
                        }
                        // 编剧
                        if (isset($arr_attribute_list['Writer']) && strlen($arr_attribute_list['Writer']) > 0)
                        {
                            $str_adaptor = htmlspecialchars($arr_attribute_list['Writer'], ENT_QUOTES);
                            $arr_assets_info['adaptor'] = $str_adaptor;
                            $arr_clip_info['adaptor'] = $str_adaptor;
                        }
                        break;
                    // 版权编目，暂无需处理
                    case 'Copyright':
                        break;
                    // 播放器编目，即打点信息，暂无需处理
                    case 'Player':
                        break;
                    default:
                        break;
                }
            }
        }
        //主媒资注入
        $add_vod_result = $this->_import_asset($arr_assets_info, $str_import_id);
//        if ($add_vod_result['ret'] != 0)
//        {
//            return $add_vod_result;
//        }
        $add_index_result = $this->_import_clip($arr_clip_info, $str_import_id);
//        if ($add_index_result['ret'] != 0)
//        {
//            return $add_index_result;
//        }
        //片源注入
        if (!empty($arr_file_info_list))
        {
            foreach ($arr_file_info_list as $arr_item)
            {
                $arr_item['import_source'] = $str_import_source;
                $add_media_result = $this->_import_media($arr_item, $str_import_id,$arr_item['file_id']);
//                if ($add_media_result['ret'] != 0)
//                {
//                    return $add_media_result;
//                }
            }
        }
    }
    /**
     * 索贝解析主媒资入库
     * @param $arr_assets_info
     * @param $str_import_id
     * @return array|multitype|void
     */
    public function _import_asset($arr_assets_info,$str_import_id)
    {
        $do_category = array(
            'base_info'=>array(
                'nns_name'=>$arr_assets_info['assets_category'],   //栏目名称支持多层目录，多层目录的时候 /分割
                'nns_import_category_id'=>'', //栏目名称支持多层目录，多层目录的时候 /分割
                'nns_cp_id'=>$arr_assets_info['asset_source'],
                'nns_import_parent_category_id'=>'',
                'nns_video_type'=>'0',  //媒资类型  0 点播 | 1 直播
            ),
        );
        $result = $this->category_action('add', $do_category);
        if($result['ret'] !=0)
        {
            return $result;
        }
        if(!isset($result['data_info']['base_info']['nns_id']) || strlen($result['data_info']['base_info']['nns_id']) <1)
        {
            return m_config::return_data(1,'创建栏目失败');
        }
        $nns_category_id = $result['data_info']['base_info']['nns_id'];

        $add_series = array(
            'base_info' => array(
                'nns_name' => $arr_assets_info['name'],
                'nns_view_type' => $arr_assets_info['view_type'],
                'nns_org_type' => '0',
                'nns_tag' => '26,',
                'nns_director' => $arr_assets_info['director'],
                'nns_actor' => $arr_assets_info['player'],
                'nns_show_time' => (isset($arr_assets_info['release_time']) &&  strlen($arr_assets_info['release_time'])>0 ) ? date("Y", strtotime($arr_assets_info['release_time'])) : date("Y"),
                'nns_view_len' => $arr_assets_info['view_len'],
                'nns_all_index' => 1,
                'nns_new_index' => 0,
                'nns_area' => '',
//                'nns_image0' => isset($arr_assets_info['bigpic']) ? $arr_assets_info['bigpic'] : '',
                'nns_image0' =>  '',
                'nns_image1' => isset($arr_assets_info['middlepic']) ? $arr_assets_info['middlepic'] : '',
                'nns_image2' => isset($arr_assets_info['smallpic']) ? $arr_assets_info['smallpic'] : '',
                'nns_image3' => '',
                'nns_image4' => '',
                'nns_image5' => '',
                'nns_summary' =>$arr_assets_info['intro'],
                'nns_remark' => '',
                'nns_category_id' => $nns_category_id,
                'nns_play_count' => '0',
                'nns_score_total' => '0',
                'nns_score_count' => '0',
                'nns_point' => '0',
                'nns_copyright_date' => (isset($arr_assets_info['release_time']) && strlen($arr_assets_info['release_time'])>0) ? date("Y", strtotime($arr_assets_info['release_time'])) : date("Y"),
                'nns_asset_import_id' => $str_import_id,
                'nns_pinyin' => $arr_assets_info['initials'],
                'nns_pinyin_length' => strlen($arr_assets_info['initials']),
                'nns_alias_name' => $arr_assets_info['subordinate_name'],
                'nns_eng_name' => '',
                'nns_language' => '',
                'nns_text_lang' => '',
                'nns_producer' => $arr_assets_info['producer'],
                'nns_screenwriter' => '',
                'nns_play_role' => '',
                'nns_copyright_range' => '',
                'nns_vod_part' => '',
                'nns_keyword' => $arr_assets_info['sreach_key'],
                'nns_import_source' => (isset($arr_assets_info['import_source']) && strlen($arr_assets_info['import_source']) > 0 )? $arr_assets_info['import_source']  : evn::get("project"),
                'nns_kind' => '',
                'nns_copyright' => '',
                'nns_clarity' => '',
                'nns_image_v' => isset($arr_assets_info['verticality_img']) ? $arr_assets_info['verticality_img'] : '',
                'nns_image_s' => isset($arr_assets_info['square_img']) ? $arr_assets_info['square_img'] : '',
                'nns_image_h' => isset($arr_assets_info['horizontal_img']) ? $arr_assets_info['horizontal_img'] : '',
                'nns_cp_id' => $arr_assets_info['asset_source'],
                'nns_conf_info' => '',
                'nns_ext_url' => '',
            ), //基本信息（存储于nns_vod表中）
            'ex_info' => array(
                'svc_item_id' => '',
                'month_clicks' => '',
                'week_clicks' => '',
                'base_id' => '',
                'asset_path' => '',
                'ex_tag' => '',
                'full_spell' => '',
                'awards' => '',
                'year' => '',
                'play_time' => '',
                'channel' => '',
                'first_spell' => '',
            ), //扩展信息（存储于nns_vod_ex表中）
        );
        //字段待修改4-14
        return $this->vod_action('add', $add_series);
    }
    /**
     * 索贝解析分集入库
     * @param $arr_clip_info
     * @param $str_import_id
     * @return array|multitype|void
     */
    public function _import_clip($arr_clip_info,$str_import_id)
    {
        $add_index = array(
            'base_info' => array(
                'nns_name' => $arr_clip_info['name'],
                'nns_index' => $arr_clip_info['index'],
                'nns_time_len' => $arr_clip_info['time_len'],
                'nns_summary' => $arr_clip_info['summary'],
                'nns_image' => $arr_clip_info['key_val_list']['pic'],
                'nns_play_count' => 0,
                'nns_score_total' => 0,
                'nns_score_count' => 0,
                'nns_video_import_id' => $str_import_id,
                'nns_import_id' => $str_import_id,
                'nns_import_source' => (isset($arr_clip_info['import_source']) && strlen($arr_clip_info['import_source']) > 0 )? $arr_clip_info['import_source']  : evn::get("project"),
                'nns_director' => isset($arr_clip_info['director']) ? $arr_clip_info['director'] : '',
                'nns_actor' => isset($arr_clip_info['player']) ? $arr_clip_info['player'] : '',
                'nns_release_time' => (isset($arr_clip_info['release_time']) &&  strlen($arr_clip_info['release_time'])>0 ) ? date("Y", strtotime($arr_clip_info['release_time'])) : date("Y"),
                'nns_update_time' => date("Y-m-d"),
                'nns_watch_focus' => '',
                'nns_cp_id' => $arr_clip_info['asset_source'],
                'nns_conf_info' => '',
                'nns_ext_url' => '',
            ),
            'ex_info' => array(
                'isintact' => $arr_clip_info['isintact'],
                'subordinate_name' => $arr_clip_info['subordinate_name'],
                'initials' => $arr_clip_info['initials'],
                'publisher' => '',
                'first_spell' => $arr_clip_info['first_spell'],
                'caption_language' => '',
                'language' => $arr_clip_info['language'],
                'region' => '',
                'adaptor' => '',
                'sreach_key' => $arr_clip_info['sreach_key'],
                'event_tag' => '',
                'year' => '',
                'sort_name' => '',
            ),
        );
        return $this->index_action('add', $add_index);
    }
    /**
     * 索贝解析片源入库
     * @param $arr_media_info
     * @param $str_import_id            //主媒资和分集的注入ID
     * @param $media_import_id          //片源注入ID
     * @return array|multitype|void
     */
    public function _import_media($arr_media_info,$str_import_id,$media_import_id)
    {
        $arr_media_info['file_path'] = str_replace("\\","/",$arr_media_info['file_path']);
        $arr_media_info['file_path'] = str_replace("//","/",$arr_media_info['file_path']);
        $temp_file_path = explode(":",$arr_media_info['file_path'],2);
        $arr_media_info['file_path'] = ltrim($temp_file_path['1'],'/');
        $cp_config = nl_cp::get_cp_config(m_config::get_dc(),$arr_media_info['asset_source']);
        $ftp_url = $cp_config['data_info']['nns_config']['down_url_real'];
        //片源参数
        $add_media = array(
            'base_info' => array(
                'nns_name' => $arr_media_info['file_name'],
                'nns_type' => 1,
                'nns_url' => $ftp_url.$arr_media_info['file_path'],
                'nns_tag' => '26,',
                'nns_mode' => $arr_media_info['file_definition'],
                'nns_kbps' => $arr_media_info['file_bit_rate'],
                'nns_content_id' => $media_import_id,
                'nns_content_state' => 0,
                'nns_filetype' => (isset($arr_media_info['file_bit_rate']) && strlen($arr_media_info['file_bit_rate']) > 0 ) ? $arr_media_info['file_bit_rate'] : 'ts',
                'nns_play_count' => '0',
                'nns_score_total' => '0',
                'nns_score_count' => '0',
                'nns_video_import_id' => $str_import_id,
                'nns_index_import_id' => $str_import_id,
                'nns_import_id' => $media_import_id,
                'nns_import_source' => (isset($arr_media_info['import_source']) && strlen($arr_media_info['import_source']) > 0 )? $arr_media_info['import_source']  : evn::get("project"),
                'nns_dimensions' => '2D',
                'nns_ext_url' => '',
                'nns_file_size' => (int)$arr_media_info['file_size'],
                'nns_file_time_len' => $arr_media_info['file_time_len'],
                'nns_file_frame_rate' => $arr_media_info['FrameRate'],
                'nns_file_resolution' => $arr_media_info['file_resolution'],
                'nns_cp_id' => $arr_media_info['asset_source'],
                'nns_ext_info' => '',
                'nns_drm_enabled' => 0,
                'nns_drm_encrypt_solution' => '',
                'nns_drm_ext_info' => '',
                'nns_domain' =>0,
                'nns_media_type' =>1,
                'nns_original_live_id' => '',
                'nns_start_time' => '',
                'nns_media_service' => '',
                'nns_conf_info' => '',
                'nns_encode_flag' =>0,
                'nns_live_to_media' => '',
                'nns_media_service_type' => '',
            ),
            'ex_info' => array(
                'file_hash' => '',
                'file_width' => '',
                'file_height' => '',
                'file_scale' => '',
                'file_coding' => '',
            ),
        );
        return $this->media_action('add', $add_media);
    }

    private function _create_result($ret = 0, $reason = 'OK', $data = array())
    {
        $arr_result = array(
            'ret'	=> $ret,
            'reason'=> $reason,
            'data'	=> $data
        );
        return $arr_result;
    }

    private function handle_picture_v3($asset_id)
    {
        $array_img = array();
        $array_img['bigpic']='';
        $array_img['middlepic']='';
        $array_img['smallpic']='';
        $array_img['horizontal_img']='';
        $array_img['verticality_img']='';
        $array_img['square_img']='';
        if(empty($this->arr_picture) || !is_array($this->arr_picture))
        {
            return $array_img;
        }
        $array_map = $this->get_map_info_v2('Picture',$this->arr_map,$asset_id);
        if(empty($array_map))
        {
            return $array_img;
        }
        $array_map_key = array_keys($array_map);
        $temp_array = array();
        foreach ($this->arr_picture as $obj_picture)
        {
            if(!in_array($obj_picture['ContentID'], $array_map_key))
            {
                continue;
            }
            //组成数据,key为图片type,值为url
            if (!isset($obj_picture['key_val_list']['Type']))
            {
                foreach ($array_map as $k_id => $val)
                {
                    if ($obj_picture['ContentID'] == $k_id)
                    {
                        $obj_picture['key_val_list']['Type'] = $val['key_val_list']['Type'];
                    }
                }
            }
            $temp_array[$obj_picture['key_val_list']['Type']] = (isset($obj_picture['key_val_list']['FileURL']) && strlen($obj_picture['key_val_list']['FileURL']) >0) ? trim($obj_picture['key_val_list']['FileURL']) : '';
        }
        $temp_array = array_filter($temp_array);
        if(empty($temp_array))
        {
            return $array_img;
        }
        $arr_combine = $this->combine_picture($array_img, $temp_array);
        return array_combine(array_keys($array_img),$arr_combine);
    }

    private function get_map_info_v2($p_type,$arr_map, $e_id)
    {
        $temp_arr = array();
        if ($p_type == 'Picture')
        {
            foreach ($arr_map as $map)
            {
                if ($map['attributes']['ElementType'] == $p_type && $map['attributes']['ParentCode'] == $e_id)
                {
                    $filter_map = $this->make_key_value_arr($map);
                    $temp_arr[$map['attributes']['ElementCode']] = $filter_map;
                }
                if (isset($temp_arr[$map['attributes']['ElementCode']]))
                {
                    continue;
                }
                if ($map['attributes']['ParentType'] == $p_type && $map['attributes']['ElementCode'] == $e_id)
                {
                    $filter_map = $this->make_key_value_arr($map);
                    $temp_arr[$map['attributes']['ParentCode']] = $filter_map;
                }
            }

        }
        else
        {
            foreach ($arr_map as $map)
            {
                if ($map['attributes']['ElementType'] == $p_type && $map['attributes']['ParentType'] != 'Picture' && $map['attributes']['ElementCode'] == $e_id)
                {
                    $filter_map = $this->make_key_value_arr($map);
                    $temp_arr[$map['attributes']['ParentCode']] = $filter_map;
                }
            }
        }
        return $temp_arr;
    }

    /**
     * 获取xml的 attr属性和key value值
     * @param unknown $xml_obj_arr
     * @return Ambigous <NULL, unknown, string>
     */
    private function make_key_value_arr($xml_obj_arr)
    {
        $key_val_array = null;
        if (isset($xml_obj_arr['attributes']) && is_array($xml_obj_arr['attributes']) && !empty($xml_obj_arr['attributes']))
        {
            foreach ($xml_obj_arr['attributes'] as $attr_key => $attr_val)
            {
                $key_val_array[$attr_key] = $attr_val;
            }
            if(!isset($key_val_array['ContentID']) || strlen($key_val_array['ContentID'])<1)
            {
                $key_val_array['ContentID'] = isset($xml_obj_arr['attributes']['ID']) ? $xml_obj_arr['attributes']['ID'] : '';
            }
            unset($xml_obj_arr['attributes']);
        }
        if (isset($xml_obj_arr['children']) && is_array($xml_obj_arr['children']) && !empty($xml_obj_arr['children']))
        {
            foreach ($xml_obj_arr['children'] as $key_list)
            {
                if (isset($key_list['attributes']['Name']) && strlen($key_list['attributes']['Name']) > 0)
                {
                    $key_val_array['key_val_list'][$key_list['attributes']['Name']] = (isset($key_list['content']) && strlen($key_list['content']) > 0) ? trim($key_list['content']) : '';
                }
            }
            unset($xml_obj_arr['children']);
        }
        return $key_val_array;
    }
    /**
     * 主媒资上下线
     *
     * @param array $content 内容
     * @param string $asset_id 主媒资ID
     * @return array
     */
    public function  line_asset($content,$asset_id)
    {
        $content['asset_type'] = isset($content['asset_type'])?$content['asset_type']:'video';
        //查询主媒资分集映射关系
        $vod_info = nl_asset_incidence_relation::query_asset_relation(m_config::$obj_dc,$content['asset_type'],$asset_id,$content['cp_id']);
        if($vod_info['ret'] !=0)
        {
            return $vod_info;
        }
        $exists_id = (isset($vod_info['data_info'][0]['nns_id']) && !empty($vod_info['data_info'][0]['nns_id'])) ? $vod_info['data_info'][0]['nns_id'] : false;
        if($exists_id === FALSE)
        {
            return array(
                "ret" => 1,
                "reason" => '媒资上下线'.$content['asset_type']."查无数据"
            );
        }
        //获取任务名称
        $task_arr = $this->get_task_name($exists_id, $content['asset_type']);
        $task_name = $task_arr['task_name'];
        //组装上下线需要的参数
        $add_asset_online = array(
            "base_info"=>array(
                'nns_vod_id'=>$exists_id,
                'nns_video_name'=>$task_name,
                'nns_action'=> ($content['action'] == '5') ? 'unline' : 'online',
                'nns_message_id'=>$content['message_id'],
                'nns_import_id'=>$asset_id,
                'nns_order'=>9999-(float)$content['order'],
                'nns_cp_id'=>$content['cp_id'],
                'nns_category_id'=>$content['category_id'],
                'nns_type'=> $content['asset_type']
            )
        );
        $re = $this->asset_online_action('add', $add_asset_online);
        return $re;
    }
    /**
     * 获取任务名称
     * @param string $video_id 视频id
     * @param string $video_type 视频类型
     * @return string task_name
     * @author yunping.yang
     * @date 2014-8-12
     */
    private function get_task_name($video_id, $video_type)
    {
        set_time_limit(0);
        $db = m_config::get_dc()->db();
        //获取任务名称
        $task_name = '';
        $asset_id = '';
        $nns_kbps = 0;
        $nns_cp_id = '';
        $nns_ext_url = '';
        $nns_url = '';
        $nns_live_to_media = 1;
        $nns_filetype = '';
        $ex_data = array();
        switch ($video_type)
        {
            case video:
                $task_name_arr = nl_db_get_one("select nns_name,nns_cp_id,nns_asset_import_id,nns_ext_url from nns_vod where nns_id='{$video_id}'", $db);
                $task_name = $task_name_arr['nns_name'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $asset_id = $video_id;
                $str_import_id = $task_name_arr['nns_asset_import_id'];
                $nns_ext_url = $task_name_arr['nns_ext_url'];
                $nns_media_encode_flag = 0;
                $nns_ext_info = '';
                $nns_tag = '';
                break;
            case BK_OP_INDEX:
                $task_name_arr = nl_db_get_one("select nns_name,nns_vod_id,nns_index,nns_cp_id,nns_import_id,nns_ext_url from nns_vod_index where nns_id='{$video_id}'", $db);
                if (strlen(trim($task_name_arr['nns_name'])) <= 0)
                {
                    $task_name_arr['nns_index1'] = (int)$task_name_arr['nns_index'] + 1;
                    $task_name_arr['nns_name'] = '第' . $task_name_arr['nns_index1'] . '集';
                }
                $task_name = '[' . $task_name_arr['nns_name'] . ']';
                $asset_id = $task_name_arr['nns_vod_id'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $str_import_id = $task_name_arr['nns_import_id'];
                $nns_ext_url = $task_name_arr['nns_ext_url'];
                $nns_media_encode_flag = 0;
                $nns_ext_info = '';
                $nns_tag = '';
                break;
            case BK_OP_MEDIA:
                $task_name_arr = nl_db_get_one("select vodindex.nns_name,vodindex.nns_index,media.nns_mode,media.nns_filetype,media.nns_tag as nns_tag,media.nns_media_type as nns_media_type,media.nns_url as nns_url,media.nns_vod_id as nns_vod_id,media.nns_kbps as nns_kbps,media.nns_cp_id as nns_cp_id,media.nns_content_id as nns_content_id,media.nns_import_id as nns_import_id,media.nns_ext_url as nns_ext_url,media.nns_ext_info as nns_ext_info,media.nns_encode_flag as nns_encode_flag  from nns_vod_media media left join nns_vod_index vodindex on media.nns_vod_index_id=vodindex.nns_id   where media.nns_id='{$video_id}'", $db);
                if (strlen(trim($task_name_arr['nns_name'])) <= 0)
                {
                    $task_name_arr['nns_index1'] = (int)$task_name_arr['nns_index'] + 1;
                    $task_name_arr['nns_name'] = '第' . $task_name_arr['nns_index1'] . '集';
                }
                $ex_data['nns_content_id'] = $task_name_arr['nns_content_id'];
                $asset_id = $task_name_arr['nns_vod_id'];
                $nns_kbps = ($task_name_arr['nns_kbps'] > 0) ? $task_name_arr['nns_kbps'] : 0;
                $task_name = '[' . $task_name_arr['nns_name'] . '] [' . $nns_kbps . '/kbps] ' . ' [' . $task_name_arr['nns_tag'] . '] ' . $task_name_arr['nns_mode'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $str_import_id = $task_name_arr['nns_import_id'];
                $nns_ext_url = $task_name_arr['nns_ext_url'];
                $nns_ext_info = $task_name_arr['nns_ext_info'];
                $nns_tag = (strlen($task_name_arr['nns_tag']) > 0) ? $task_name_arr['nns_tag'] : '';
                $nns_media_encode_flag = (isset($task_name_arr['nns_encode_flag']) && in_array($task_name_arr['nns_encode_flag'], array('0', '1', '2'))) ? $task_name_arr['nns_encode_flag'] : 0;
                $nns_tag = $task_name_arr['nns_tag'];
                $nns_url = $task_name_arr['nns_url'];
                $nns_filetype = $task_name_arr['nns_filetype'];
                $nns_live_to_media = $task_name_arr['nns_media_type'];
                break;
            case BK_OP_LIVE:
                $task_name_arr = nl_db_get_one("select nns_name,nns_cp_id,nns_import_id,nns_integer_id from nns_live where nns_id='{$video_id}'", $db);
                $task_name = $task_name_arr['nns_name'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $asset_id = $video_id;
                $str_import_id = (strlen($task_name_arr['nns_import_id']) > 0) ? $task_name_arr['nns_import_id'] : $task_name_arr['nns_integer_id'];
                $nns_ext_url = '';
                $nns_media_encode_flag = 0;
                $nns_ext_info = '';
                $nns_tag = '';
                break;
            case BK_OP_LIVE_MEDIA:
                $task_name_arr = nl_db_get_one("select live_index.nns_index,media.nns_mode,media.nns_live_id as nns_vod_id,media.nns_tag as nns_tag,media.nns_kbps as nns_kbps,media.nns_cp_id as nns_cp_id,media.nns_content_id as nns_content_id,media.nns_ext_url as nns_ext_url  from nns_live_media as media left join nns_live_index live_index on media.nns_live_index_id=live_index.nns_id   where media.nns_id='{$video_id}'", $db);
                if (strlen(trim($task_name_arr['nns_name'])) <= 0)
                {
                    $task_name_arr['nns_index1'] = (int)$task_name_arr['nns_index'] + 1;
                    $task_name_arr['nns_name'] = '第' . $task_name_arr['nns_index1'] . '集';
                }
                $ex_data['nns_content_id'] = $task_name_arr['nns_content_id'];
                $asset_id = $task_name_arr['nns_vod_id'];
                $nns_kbps = ($task_name_arr['nns_kbps'] > 0) ? $task_name_arr['nns_kbps'] : 0;
                $task_name = '[' . $task_name_arr['nns_name'] . '] [' . $nns_kbps . '/kbps] ' . ' [' . $task_name_arr['nns_tag'] . '] ' . $task_name_arr['nns_mode'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $str_import_id = $task_name_arr['nns_content_id'];
                $nns_ext_url = $task_name_arr['nns_ext_url'];
                $nns_media_encode_flag = 0;
                $nns_ext_info = '';
                $nns_tag = '';
                break;
            case BK_OP_PLAYBILL:
                $task_name_arr = nl_db_get_one("select nns_name,nns_cp_id,nns_playbill_import_id,nns_ext_url,nns_begin_time,nns_live_id from nns_live_playbill_item where nns_id='{$video_id}'", $db);
                if (isset($task_name_arr['nns_live_id']) && strlen($task_name_arr['nns_live_id']))
                {
                    $task_name_arr_live = nl_db_get_one("select nns_name from nns_live where nns_id='{$task_name_arr['nns_live_id']}'", $db);
                }
                $live_name_temp = isset($task_name_arr_live['nns_name']) ? $task_name_arr_live['nns_name'] : '';
                $task_name = $live_name_temp . '] [' . $task_name_arr['nns_begin_time'] . '] [' . $task_name_arr['nns_name'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $asset_id = $video_id;
                $str_import_id = $task_name_arr['nns_playbill_import_id'];
                $nns_ext_url = $task_name_arr['nns_ext_url'];
                $nns_media_encode_flag = 0;
                $nns_ext_info = '';
                $nns_tag = '';
                break;
            case BK_OP_FILE:
                $task_name_arr = nl_db_get_one("select nns_name,nns_cp_id,nns_import_id,nns_ext_url from nns_file_package where nns_id='{$video_id}'", $db);
                $task_name = $task_name_arr['nns_name'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $asset_id = $video_id;
                $str_import_id = $task_name_arr['nns_import_id'];
                $nns_ext_url = $task_name_arr['nns_ext_url'];
                $nns_ext_info = '';
                $nns_media_encode_flag = 0;
                $nns_tag = '';
                break;
            case BK_OP_PRODUCT:
                $task_name_arr = nl_db_get_one("select nns_order_name as nns_name,nns_cp_id,nns_order_number as nns_import_id from nns_product where nns_id='{$video_id}'", $db);
                $task_name = $task_name_arr['nns_name'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $asset_id = $video_id;
                $str_import_id = $task_name_arr['nns_import_id'];
                $nns_ext_url = '';
                $nns_ext_info = '';
                $nns_media_encode_flag = 0;
                $nns_tag = '';
                break;
            case  BK_OP_SEEKPOINT:
                $task_name_arr = nl_db_get_one("select * from nns_vod_index_seekpoint where nns_id='{$video_id}'", $db);
                $task_name = $task_name_arr['nns_name'];
                $nns_cp_id = (strlen($task_name_arr['nns_cp_id']) > 0) ? $task_name_arr['nns_cp_id'] : 0;
                $asset_id = $video_id;
                $str_import_id = $task_name_arr['nns_import_id'];
                $nns_ext_url = '';
                $nns_ext_info = '';
                $nns_media_encode_flag = 0;
                $nns_tag = '';
                break;
        }
        if ($video_type == BK_OP_VIDEO || $video_type == BK_OP_PLAYBILL || $video_type == BK_OP_FILE || $video_type == BK_OP_LIVE)
        {
            $task_name = '[' . $task_name . ']';
        } else if ($video_type == BK_OP_LIVE_MEDIA)
        {
            $video_name = nl_db_get_col("select nns_name from nns_live where nns_id='{$asset_id}'", $db);
            $task_name = '[' . $video_name . '] ' . $task_name;
        } else
        {
            $video_name = nl_db_get_col("select nns_name from nns_vod where nns_id='{$asset_id}'", $db);
            $task_name = '[' . $video_name . '] ' . $task_name;
        }
        $array = array(
            'task_name' => $task_name,
            'asset_id' => $asset_id,
            'nns_kbps' => $nns_kbps,
            'cp_id' => $nns_cp_id,
            'ex_data' => $ex_data,
            'import_id' => $str_import_id,
            'nns_ext_url' => $nns_ext_url,
            'nns_ext_info' => $nns_ext_info,
            'nns_media_encode_flag' => $nns_media_encode_flag,
            'nns_tag' => $nns_tag,
            'nns_url' => $nns_url,
            'nns_live_to_media' => $nns_live_to_media,
            'nns_filetype' => $nns_filetype,
        );
        /*print_r($array);die;*/
        return $array;
    }

    public function status($message_id)
    {

    }

    /**
     * 消息队列注入播控统一反馈给芒果二级，组装消息结构
     * @param int $state
     * @param string $reason
     * @param array $info
     */
    public function create_xml_respond_msg_to_csp($state=0, $reason='',$info=array())
    {
        if ($state == 0)
        {
            \m_config::write_callback_log('不是最终注入下游成功状态不进行反馈', $this->source_id, $this->msg_id);
            return;
        }

        $site_url = $this->arr_cp_config['data_info']['nns_config']['site_callback_url'];

        \m_config::write_message_execute_log('消息处理结果:' . var_export($reason, true), $this->source_id);
        \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '反馈到上游地址信息：站点地址为-' . $site_url, $this->source_id, $this->msg_id);

        //反馈状态转换
        $state = $state== 0 ?  0 : -1;
        if(!empty($site_url))
        {
            $params = array(
                'msgid' => $this->msg_id,
                'CmsResult' => $state,
                'ResultMsg' => $reason
            );
            if(!empty($info))
            {
                $params['info'] = $info;
            }
            $this->notify_msg($params,true,$site_url);
        }
        else
        {
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '没有配置站点信息', $this->source_id, $this->msg_id);
        }
    }

    /**
     * @description:播控注入cdn后统一反馈给二级
     * @author:xinxin.deng
     * @date: 2018/3/2 9:59
     * @param $message_id //消息id
     * @param $code //状态码，失败1，成功0
     * @param $reason //原因描述
     * @param $arr_data //封装好了的反馈信息 array(
     *                                          'cdn_id' => ,注入cdn的id
     *                                          'site_id' => ,配置的站点id
     *                                          'mg_asset_type' => ,注入媒资类型
     *                                          'mg_asset_id' => ,主媒资的消息注入id
     *                                          'mg_part_id' => ,分集的消息注入id
     *                                          'mg_file_id' => ,片源的消息注入id,
     *                                          'is_finally' =>0, 0表示最终状态,反馈的时候将其unset掉
     *                                          );
     * @param $sp_id //sp_id
     */
    public function is_ok($message_id, $code, $reason, $arr_data, $sp_id)
    {
        $arr_sp_data = \m_config::_get_sp_info($sp_id);
        $sp_config = isset($arr_sp_data['data_info']['nns_config']) ? $arr_sp_data['data_info']['nns_config'] : array();
        //不是最终状态不进行反馈
        if (($code == 5 || $code == 98 || $code === 0) && (!isset($arr_data['is_finally']) || $arr_data['is_finally'] !== 0 || $arr_data['is_finally'] != null))
        {
            \m_config::write_callback_log('不是最终成功状态不进行反馈', 'starcor', $message_id);
            return;
        }
        unset($arr_data['is_finally']);
        //兼容湖南电信二级消息反馈，1表示成功，0表示失败。
        $code = $code === 0 ? 1 : 0;
        $flag_message_feedback_enabled = (!isset($sp_config['message_feedback_enabled']) || $sp_config['message_feedback_enabled'] !=1) ? true : false;
        if(!$flag_message_feedback_enabled || !isset($sp_config['message_feedback_mode']) || $sp_config['message_feedback_mode'] != 0)
        {
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '不允许反馈或者反馈模式不正确：
        [message_feedback_enabled]=' . $sp_config['message_feedback_enabled'] . 'message_feedback_mode=' . $sp_config['message_feedback_mode'], 'hdty', $message_id);
            return;
        }

        //查询sp的上报地址/芒果使用站点ID
        if(isset($sp_config['site_callback_url']) && strlen($sp_config['site_callback_url']) > 0)
        {
            $xml_info = array(
                'msgid' => $message_id,
                'state' => $code,
                'msg' => $reason,
                'info' => $arr_data,
            );


            $xml = self::_build_notify_xml($xml_info);
            $data = array(
                'cmsresult' => $xml,
            );
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '站点反馈地址为:' . var_export($sp_config['site_callback_url'], true) . ',反馈
        数据为:' . $xml, 'hdty', $message_id);
            $http_header = array("Content-Type: application/x-www-form-urlencoded;charset=UTF-8");
            $http_curl = new np_http_curl_class();
            for ($i = 0; $i < 3; $i++) {
                //访问媒资注入接口
                $re = $http_curl->post($sp_config['site_callback_url'], http_build_query($data), $http_header, 2);
                $curl_info = $http_curl->curl_getinfo();
                $http_code = $curl_info['http_code'];
                \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '循环请求第' . $i . '次(如果请求返回post结果为true并且状态码不是200,就会默认循环3次,状态码为200,
            就跳出循环),' . '请求返回post结果为:' . $re . '请求返回状态为:' . var_export($http_code, true) . ',反回数据为:' . var_export($curl_info, true) . ',
            访问POST结果为:' . var_export($re, true), 'hdty', $message_id);

                if ($http_code != 200 && (int)$re === 1)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
        }
        return;
    }


    /**
     * @description:组装反馈的XML
     * @author:xinxin.deng
     * @date: 2018/2/26 14:25
     * @param $params
     * @return string|void
     */
    public function _build_notify_xml($params)
    {
        if(!is_array($params) || empty($params))
        {
            return ;
        }
        $dom = new DOMDocument('1.0', 'utf-8');
        $xmlresult = $dom->createElement('xmlresult');
        $dom->appendChild($xmlresult);
        foreach ($params as $key=>$value)
        {
            $$key = $dom->createElement($key);
            $xmlresult->appendchild($$key);
            if(!empty($value) && is_array($value))
            {
                foreach ($value as $k=>$val)
                {
                    $$k = $dom->createElement($k);
                    $$key->appendchild($$k);
                    //创建元素值
                    $content = $dom->createTextNode($val);
                    $$k->appendchild($content);
                }
            }
            else
            {
                //创建元素值
                $text = $dom->createTextNode($value);
                $$key->appendchild($text);
            }
        }
        return $dom->saveXML();
    }


    /**
     * 进行消息反馈
     * @param $params
     * @param bool $bool
     * @param string $site_url
     * @return array|string|void
     */
    public function notify_msg($params, $bool=false, $site_url='')
    {
        $http_curl = new np_http_curl_class();
        $xml = $this->_build_notify_xml($params);
        \m_config::write_callback_log( '[' . date('Y-m-d H:i:s') . ']' . '反馈给上游的数据为：' . var_export($xml, true), $this->source_id, $this->msg_id);
        if(!$bool)//是否异步反馈通知上游
        {
            return $xml;
        }
        if(!empty($site_url))
        {
            $xml = array('cmsresult'=> $xml);
            $http_header = array("Content-Type: application/x-www-form-urlencoded;charset=UTF-8");
            $response = $http_curl->post($site_url, http_build_query($xml), $http_header,2);
            $curl_info = $http_curl->curl_getinfo();
            \m_config::write_callback_log( '[' . date('Y-m-d H:i:s') . ']' . '上游接收到反馈后响应的结果为：' . $response . ',POST反馈数据为：' . var_export($curl_info, true), $this->source_id, $this->msg_id);
            if ($response === 0 )
            {
                \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . 'post地址请求失败', $this->source_id, $this->msg_id);
                return;
            }
        }
        else
        {
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '没有配置反馈地址', $this->source_id, $this->msg_id);
        }
    }

    /**
     * 合并图片类型
     * @param $arr_img
     * @param $arr_temp
     * @return array
     */
    private function combine_picture($arr_img, $arr_temp)
    {
        $arr_img = array_values($arr_img);
        foreach ($arr_temp as $k=> $item)
        {
            $arr_img[$k-1] = $item;
        }
        return $arr_img;
    }
}